so if in your action you do 

@relationship = current_user.relationships.build(followed_id: @user.id)

you should have a variable called relationship on your view:

<%= form_for(relationship) do |f| %>
  <div><%= f.hidden_field :followed_id %></div>
  <%= f.submit "Follow", class: "btn btn-large btn-primary" %><% end %>


On Tuesday, 4 June 2013 17:31:07 UTC+2, dasibre wrote:
>
> 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 method
>
> def 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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/97395a3c-65c2-4fd8-81ac-922479a0bab7%40googlegroups.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to