Reputation: 4400
i have 2 controllers methods create and show
def create
@message2 = Message.new(params[:message])
if @message2.valid?
@message2 = current_user.sent_messages.create(params[:message])
redirect_to @message2.receiver
else
redirect_to :back
end
end
and
def show
@message = Message.find(params[:id])
if [email protected]
@message.is_read=true
@message.save
@message2=Message.new(:receiver_id=>@message.sender, :sender_id=>current_user,:theme=>@message.theme)
else
@message2=Message.new(:receiver_id=>@message.receiver, :sender_id=>current_user,:theme=>@message.theme)
end
end
my form
= form_for(@message2) do |f|
%p
Content:
%br
= f.text_area :content ,:rows => 5,:id => "text_area",
:cols => 45
.actions
= f.submit
in show view i have form which initialize @message2.content but create action cleans all parameters which I set in show action and sets only content value. How to make my form to append parameters (not to clean old)?
Upvotes: 1
Views: 2705
Reputation: 14179
def create
@message2 = current_user.sent_messages.new(params[:message])
if @message2.save
redirect_to @message2.receiver
else
render :action => :show
end
end
Here's how your create
action should look. This is a commonly used Rails idiom.
It will render the form correctly, because the instance variable is still there.
Upvotes: 1