Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3 Routes Issue
    primarykey
    data
    text
    <p>I am a beginning developer, and I was able to successfully use this tutorial (I'm in Rails 3): <a href="http://www.binarylogic.com/2008/11/16/tutorial-reset-passwords-with-authlogic/" rel="nofollow">http://www.binarylogic.com/2008/11/16/tutorial-reset-passwords-with-authlogic/</a> to allow for users to reset their passwords, however I also have a customer model that I need to do this for, and I'm running into issues (listed below code). I think the error is my routing, but I'm not sure how to fix it.</p> <p>routes.rb</p> <pre><code>resources :password_resets do get 'edit_customer' post 'edit_customer' end </code></pre> <p>password_resets_controller.rb</p> <pre><code>class PasswordResetsController &lt; ApplicationController before_filter :load_user_using_perishable_token, :only =&gt; [:edit, :update] before_filter :load_customer_using_perishable_token, :only =&gt; [:edit_customer, :update_customer] before_filter :require_no_user, :require_no_customer def new render end def create @user = User.find_by_email(params[:email]) @customer = Customer.find_by_email(params[:email]) if @user @user.deliver_password_reset_instructions! flash[:notice] = "Instructions to reset your password have been emailed to you. " + "Please check your email." redirect_to new_user_session_path elsif if @customer @customer.deliver_customer_password_reset_instructions! flash[:notice] = "Instructions to reset your password have been emailed to you. " + "Please check your email." redirect_to new_customer_session_path end else flash[:notice] = "No account was found with that email address" render :action =&gt; :new end end def edit render end def edit_customer #redirect_to edit_customer_password_resets_path end def update @user.password = params[:user][:password] @user.password_confirmation = params[:user][:password_confirmation] if @user.save flash[:notice] = "Password successfully updated" redirect_to new_user_session_path else render :action =&gt; :edit end end def update_customer @customer.password = params[:customer][:password] @customer.password_confirmation = params[:customer][:password_confirmation] if @customer.save flash[:notice] = "Password successfully updated" redirect_to new_customer_session_path else render :action =&gt; :edit end end private def load_user_using_perishable_token @user = User.find_using_perishable_token(params[:id]) unless @user flash[:notice] = "We're sorry, but we could not locate your account." + "If you are having issues try copying and pasting the URL " + "from your email into your browser or restarting the " + "reset password process." redirect_to new_user_session_path end end def load_customer_using_perishable_token @customer = Customer.find_using_perishable_token(params[:id]) unless @customer flash[:notice] = "We're sorry, but we could not locate your account." + "If you are having issues try copying and pasting the URL " + "from your email into your browser or restarting the " + "reset password process." #redirect_to new_customer_session_path end end end </code></pre> <p>MODELS user.rb model</p> <pre><code>def deliver_password_reset_instructions! reset_perishable_token! UserMailer.password_reset_instructions(self).deliver end </code></pre> <p>customer.rb model</p> <pre><code>def deliver_customer_password_reset_instructions! reset_perishable_token! UserMailer.customer_password_reset_instructions(self).deliver end </code></pre> <p>VIEWS password_resets/new</p> <pre><code>&lt;% form_tag password_resets_path do %&gt; &lt;p&gt;Email:&lt;/p&gt; &lt;%= text_field_tag "email" %&gt;&lt;br /&gt; &lt;br /&gt; &lt;%= submit_tag "Reset my password" %&gt; &lt;% end %&gt; </code></pre> <p>password_resets/edit</p> <pre><code>&lt;% form_for @user, :url =&gt; password_reset_path, :method =&gt; :put do |f| %&gt; &lt;%= f.label :password %&gt;&lt;br /&gt; &lt;%= f.password_field :password %&gt; &lt;%= f.label :password_confirmation %&gt; &lt;%= f.password_field :password_confirmation %&gt; &lt;%= f.submit "Change my password and log me in"%&gt; &lt;% end %&gt; </code></pre> <p>password_resets/edit_customer</p> <pre><code>&lt;% form_for @customer, :url =&gt; password_reset_path, :method =&gt; :put do |f| %&gt; &lt;%= f.label :password %&gt;&lt;br /&gt; &lt;%= f.password_field :password %&gt; &lt;%= f.label :password_confirmation %&gt; &lt;%= f.password_field :password_confirmation %&gt; &lt;%= f.submit "Change my password and log me in" %&gt; &lt;% end %&gt; </code></pre> <p>It works perfectly for the code that does not have "customer" appended to it. The token generates, and I can get the email to send with the same format for the url: /password_resets//edit_customer</p> <p>However, it receives an error when I try to pull up the url. With the code above, I receive this error: "No route matches {:action=>"show", :controller=>"password_resets"}" - I can also see that it interprets the :id to be the id of the controller (which is different than how the user one works - it correctly interprets the id as the token.</p> <p>I have experimented a lot:</p> <ul> <li>change :id in controller for edit_customer in load_customer_using_perishable_token to perishable_token, customer.perishable_token, @customer.perishable_token)</li> <li>tried to append these to "get 'edit_customer'" using the path helper (=> "cust_pass") - :path, :path_name, :as so i could change the url to cust_pass_path</li> <li>i even tried to add this to the routes just to see if it would work match '/password_resets/:id/edit_customer' => 'password_resets#edit_customer'</li> </ul> <p>So I stumped. Any help would be greatly appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload