Ruby on Rails
Tuesday, June 4, 2013
I have this form, everything works fine, but I would like to move the current_user.relationships.build logic to the controller. <%= form_for(current_user.relationships.build(followed_id: @user.id)) do |f| %> <div><%= f.hidden_field :followed_id %></div> <%= f.submit "Follow", class: "btn btn-large btn-primary" %> <% end %>
Controller Relationships create methoddef create @user = User.find(params[:relationship][:followed_id]) current_user.follow!(@user) redirect_to @user
end
-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/213638fe-9758-4107-83d7-c6ee1f20d9b3%40googlegroups.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment