2012-07-03 34 views
10

だから私は、次のようなエラーに実行し続ける:Railsルーティングエラー? 「ルート一致しないNO」

No route matches {:action=>"show", :controller=>"users"}

私は熊手ルートを実行しようと、私はルートが存在していることを見ることができます:

user   GET   /users/:id(.:format)  users#show 
       PUT   /users/:id(.:format)  users#update 
       DELETE  /users/:id(.:format)  users#destroy 

しかし、私はしようとするたびに訪問ページ"https://stackoverflow.com/users/1"(1はユーザーID)、上記のエラーが表示されます。何か案は?ありがとう!ここで

は私routes.rbです:

SampleApp::Application.routes.draw do 
    root to: 'static_pages#home' 

    resources :users 
    resource :sessions, only: [:new, :create, :destroy] 


    match '/signup', to: 'users#new' 
    match '/signin', to: 'sessions#new' 
    match '/signout', to: 'sessions#destroy', via: :delete 

    match '/help', to: 'static_pages#help' 
    match '/about', to: 'static_pages#about' 
    match '/contact', to: 'static_pages#contact' 

ここに私のusers_controller.rbです:

root :to 'static_pages#home' 

(というよりもroot to:)を、そして最後に移動:

class UsersController < ApplicationController 

    before_filter :signed_in_user, only: [:index, :edit, :update] 
    before_filter :correct_user, only: [:edit, :update] 

    def show 
    @user = User.find(params[:id]) 
    end 

    def new 
    @user = User.new 
    end 

    def create 
    @user = User.new(params[:user]) 
    if @user.save 
     sign_in @user 
     flash[:success] = "Welcome to the Paper Piazza!" 
     redirect_to @user 
    else 
     render 'new' 
    end 
    end 

    def edit 
    @user = User.find(params[:id]) 
    end 

    def update 
    if @user.update_attributes(params[:user]) 
     flash[:success] = "Profile updated" 
     sign_in @user 
     redirect_to @user 
    else 
     render 'edit' 
    end 
    end 

    def index 
    @users = User.paginate(page: params[:page]) 
    end 

    private 

    def signed_in_user 
     unless signed_in? 
     store_location 
     redirect_to signin_path, notice: "Please sign in." 
     end 
    end 

    def correct_user 
     @user = User.find(params[:id]) 
     redirect_to(root_path) unless current_user?(@user) 
    end 
end 
+0

routes.rbファイルを表示 –

+0

'/ users/1 /'は動作しますか? – sarnold

+0

いいえ、 '/ users/1 /'は動作していないようです。 – user1497531

答えて

1

タイプミスを修正してくださいブロックのライン。違いがあるのか​​どうか、私に知らせてください!

何奇妙だが、私は単純に読み込み、ルーティングファイルで新鮮なプロジェクトを構築していることである:私は、コンソールでこれを実行したとき、私はあなたが見ている同じエラーを得た

RoutingTest::Application.routes.draw do 
    resources :users 
    root :to => "static_pages#home" 
end 

>> r = Rails.application.routes ; true 
=> true 
>> r.recognize_path("https://stackoverflow.com/users/1") 
=> ActionController::RoutingError: No route matches "/users" 

...しかし、私は少し古いプロジェクトで同じことを実行したときに、私が取得:

>> r = Rails.application.routes ; true 
=> true 
>> r.recognize_path("https://stackoverflow.com/users/1") 
=> {:action=>"show", :controller=>"users", :id=>"1"} 

だから私は少しconfidを持っています私があなたに話していることが違いを生み出すことを誓う。 (それ以外にも、Rails.application.routesのトリックはコンソールのパスを確認するのに便利です)。

+0

予約された名前に注意してください。 static_pagesを使用せずに何を得るかを見てみてください。 – bcackerman

0

私は同様の問題がありましたが、私はルートページを返すだけでしたが、rake routesに表示されます。特定のネームスペースのすべての開発者によれば、root to: (routing)は常に最後になければなりません。これはルートに関するすべての呼び出しがファイルの先頭にあるべきであると言うルーティングに関するRailsガイド(http://guides.rubyonrails.org/routing.html#using-rootを参照)と矛盾しています。それは間違いなく私のために働いていなかった。面白い...

関連する問題