Sunday 15 July 2012

ruby on rails - NoMethodError in ConfirmationController -


I am trying to solve the following problem for a few days. Forgive me if this is a common problem because I'm new to the rail and probably can not query the exact question / keyword in StackVareflow or Google.

I am creating a system where the user will receive an invitation email, click on a unique link, take it to the page where it can accept or reject the invitation. I'm stuck on the part where the user accepts or rejects the invitation.

I have made it around two controllers: an invitation controller and confirmation controller. The invitation controller creates a record containing a name, an email, and a specific generated token controller then emails a link to the defined email with a token. The link indicates the confirmation controller and passes the unique token from the invitation. However, when clicking on the link and accepting the invitation, I get the following error:

  NoMethodError # Confirmation in Confirmation Method `update_attribute 'for Nil: NilClass   

Here are some code to solve this problem:

Confirmation_translator RB

  class confirmation controller & lt; ApplicationController def new @confirmation = invitation.find_by_invite_token (params [: invite_token]) Confirm enddef if @confirmation.update_attribute (: accepted, true) Flash [: success] = "Invitation confirmation!" Redirect_to 'static_pages / home' and Flash [: notice] = "failed :(" 'static_pages / home' end end end   

path.rb

  For confirmation / confirmation: 'Confirmation # Confirmation'   

Click here to app / ideas / confirmation / accept: & lt;% = link_to "Confirm" ,: Adjuster = & gt; "Confirmation" ,: verb = & gt; "Confirm"%>

You also invite to the confirm method.

If no invitation is received, you get an exception Want to train

  def confirm @confirmation = invitation.find_by_invite_token! (Params [: invite_token]) @ confirmation.update _... end   

No exceptions will be extended. You may want to manually check with one condition in the following case. Confirm DIF Confirmation = Invitation.Find_b_in Vite_token (params [: invite_token] ) If @confirmation @ confirmation.update_... else # some end and

No comments:

Post a Comment