I have a form:
<%= form_for(@message) do |f| %>
That’s located in my groups#show page. What I want to do is build an association with the current user, message id and current group. I have nailed the first two just fine with the following code in my MessagesController but I know I’m trying to find my @group_id after the params have been changed:
def create
@message = Message.new(:message => params[:message],
:source => "web")
respond_to do |format|
if @message.save
current_user.envelopes.create!(:user_id => current_user.id, :group_id => @group_id, :message_id => @message.id)
format.html { redirect_to(group_path(@group_id), :notice => 'Message was sent.') }
else
format.html { render :action => "new" }
end
end
end
What I want to know is where should I catch the @group_id so that when they send a message the envelopes association is created and the user is redirected back to the group page they were just one (with the new message there now).
Thanks a lot!
If i’ve understood your problem correctly, you could stick the Group Id into the form as a hidden field: