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:, prog_id:, status: "pending")
    redirect_to @prog, notice: "Programme is added"

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

<% @prog.users.each do |user| %>
<%= link_to "#{} accept", controller: "/enrollments", action: "accept", method: "post", 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
To post to this group, send email to
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment