diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index bbc6a35d4..d6c6d7b51 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -50,8 +50,12 @@ class MessagesController < ApplicationController offset(@reply_pages.offset). to_a - @reply = Message.new(:subject => "RE: #{@message.subject}") - render :action => "show", :layout => false if request.xhr? + @reply = Message.new(:subject => "RE: #{@message.subject}") unless @reply + if request.xhr? + render :action => "show", :layout => false + else + render :action => "show" + end end # Create a new topic @@ -77,13 +81,18 @@ class MessagesController < ApplicationController @reply.author = User.current @reply.board = @board @reply.safe_attributes = params[:reply] + @reply.save_attachments(params[:attachments]) @topic.children << @reply if !@reply.new_record? call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply}) - attachments = Attachment.attach_files(@reply, params[:attachments]) render_attachment_warning_if_needed(@reply) + flash[:notice] = l(:notice_successful_update) + else + if @reply.errors.include?(:content) && @reply.saved_attachments.blank? + @reply.errors.delete(:content) + end + (show and return) unless @reply.errors.blank? end - flash[:notice] = l(:notice_successful_update) redirect_to board_message_path(@board, @topic, :r => @reply) end diff --git a/app/views/messages/_form.html.erb b/app/views/messages/_form.html.erb index 7d3a9c59f..24f454516 100644 --- a/app/views/messages/_form.html.erb +++ b/app/views/messages/_form.html.erb @@ -34,5 +34,5 @@

<%= l(:label_attachment_plural) %>
-<%= render :partial => 'attachments/form', :locals => {:container => @message} %>

+<%= render :partial => 'attachments/form', :locals => {:container => (replying ? @reply : @message)} %>

diff --git a/app/views/messages/show.html.erb b/app/views/messages/show.html.erb index b8abf0321..cbb5cb112 100644 --- a/app/views/messages/show.html.erb +++ b/app/views/messages/show.html.erb @@ -23,6 +23,7 @@

<%= avatar(@topic.author) %><%= @topic.subject %>

+<%= error_messages_for 'reply' %>

<%= authoring @topic.created_on, @topic.author %>

@@ -81,7 +82,7 @@ <% if !@topic.locked? && authorize_for('messages', 'reply') %>

<%= toggle_link l(:button_reply), "reply", :focus => 'message_content' %>

-