Skip to content

Instantly share code, notes, and snippets.

@majornorth
Created June 15, 2013 17:27
Show Gist options
  • Save majornorth/5788845 to your computer and use it in GitHub Desktop.
Save majornorth/5788845 to your computer and use it in GitHub Desktop.
The problem I was having was that the activity ID wasn't being received by the controller method. In params, I had [:activity] and not [:user]. Basically, the form and controller are adding a record to the join table for activities_users, submitting an ID for both activity_id and user_id. I got the help of my roommate, who is a programmer, and n…
<h2>Favorite Activities</h2>
<ul>
<% User.find(current_user.id).activities.each do |a| %>
<li><%= a.name %>
<%= form_for @user, :url => removefavorite_path do |f| %>
<%= f.hidden_field :activity_id, :value => a.id %>
<%= f.submit('Remove') %>
<% end %>
</li>
<% end %>
</ul>
def addFavorite
Activity.find(params[:user][:activity_id]).users << current_user
redirect_to :back
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment