Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMatthew Pierce
15,779 PointsNo route matches {:action=>"update"
Hey!
I can't get past the first run of rspec on this video, as I receive a different error which i cannot solve. (I'm using project files from last video.)
Here is the error I receive:
1) PasswordResetsController PATCH update with no token found renders the edit page
Failure/Error: patch :update, id: 'notfound', user: {password: 'newpassword1', password_confirmation: 'newpassword1'}
ActionController::UrlGenerationError:
No route matches {:action=>"update", :controller=>"password_resets", :id=>"notfound", :user=>{:password=>"newpassword1", :password_confirmation=>"newpassword1"}}
# ./spec/controllers/password_resets_controller_spec.rb:75:in `block (4 levels) in <top (required)>'
The relevant section in password_resets_controller_spec.rb:
describe "PATCH update" do
context "with no token found" do
it "renders the edit page" do
patch :update, id: 'notfound', user: {password: 'newpassword1', password_confirmation: 'newpassword1'}
expect(response).to render_template('edit')
end
end
end
password_resets_controller.rb:
class PasswordResetsController < ApplicationController
def new
end
def create
user = User.find_by(email: params[:email])
if user
user.generate_password_reset_token!
Notifier.password_reset(user).deliver
flash[:success] = "Password reset instructions sent! Please check your email."
redirect_to login_path
else
flash.now[:notice] = "Email not found."
render action: 'new'
end
end
def edit
@user = User.find_by(password_reset_token: params[:id])
if @user
else
render file: 'public/404.html', status: :not_found
end
end
def update
user = User.find_by(password_reset_token: params[:id])
if user
else
render template: 'edit'
end
end
end
routes.rb:
Rails.application.routes.draw do
get "/login" => "user_sessions#new", as: :login
delete "/logout" => "user_sessions#destroy", as: :logout
resources :users
resources :user_sessions, only: [:new, :create]
resources :password_resets, only: [:new, :create, :edit]
resources :todo_lists do
resources :todo_items do
member do
patch :complete
end
end
end
root 'todo_lists#index'
Any help would be appreciated, I'm stuck!
1 Answer
Tommy Bregar
10,847 PointsHi Matthew,
The reason you're getting that error is because of this line:
resources :password_resets, only: [:new, :create, :edit]
Which tells rails to only create routes for those actions. Try adding :update into your only: array like this:
resources :password_resets, only: [:new, :create, :edit, :update]