Vitalis wrote in post #1110889:> <%= link_to "#{user.email} accept", controller:
"/enrollments", action:
> "accept", method: "post", id: user.id, id: @prog %>/
> 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?
<%= link_to "#{user.email} accept", controller:
"/enrollments",
action: "accept", method: "post", id: user.id, prog_id:
@prog.id %>
before_filter :load_prog
def create
Enrollment.create(user_id: current_user.id, prog_id: @prog.id, status:
"pending")
redirect_to @prog, notice: "Programme is added"
end
def accept
@enrollment.status = "accepted"
@enrollment.save!
redirect_to progs_path, notice: "added"
end
private
def load_prog
@prog = Prog.find(params[:prog_id])
end
If you decide to use a before_filter as shown here make sure you pass
the Prog ID as "prog_id" for all actions.
P.S. It is generally considered good practice to avoid abbreviations in
domain objects. What is a "Prog"? Could be Program, could be
Progression, etc. If you mean "Program" then use "Program"
as your class
name and variable references. There are exceptions to every rule, such
as Proc objects and abbreviations that are very well understood by
everyone. it''s still good practice to avoid them whenever there is a
possibility of ambiguity.
--
Posted via http://www.ruby-forum.com/.
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/a1001cd2302230e5e9931e4b68c60039%40ruby-forum.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.