Ruby on Rails Friday, May 31, 2013

I have has_many through for User, Prog and Enrollment models. Idea is that User is able to add Prog to his profile and Prog is able to remove association from Enrollment or update status attribute.

  def create
    @prog = Prog.find(params[:id])
    Enrollment.create(user_id: current_user.id, prog_id: @prog.id, status: "pending")
    redirect_to @prog, notice: "Programme is added"
  end

   def accept
     @enrollment = Enrollment.find_by_user_id(params[:id])
     @enrollment.status = "accepted"
     @enrollment.save!
    redirect_to progs_path, notice: "added"
  end

<% @prog.users.each do |user| %>
<%= link_to "#{user.email} accept", controller: "/enrollments", action: "accept", method: "post", id: user.id, id: @prog %>/
<% end %>

I understand that accept method is lack of @prog to find right column in Enrollment table, but I don't undestand how do I pass this id?

--
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/ed52ec29-c422-4d70-9fdf-bb10a4103578%40googlegroups.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment