2011-06-27 22 views
0

routes.rbをsimple_navigationの宝石とレール3.0.9

PASFramework::Application.routes.draw do |map| 

    resources :users do 
    collection do 
     get :index 
     get :edit 
     post :update 
     get :show 
    end 
end 

    root :to => 'users#index' 

end 

============================== ==================================== navigation.rb

# Configures your navigation 

SimpleNavigation::Configuration.run do |navigation| 
    navigation.items do |primary| 
    primary.item :users, 'Welcome User', root_path do |users| 
     users.item :edit, 'Edit Profile', edit_users_path 
    end 
    end 

エンド

================================ ==================

User_controllえー

class UsersController < ApplicationController 
    def index 
    user = current_facebook_user.fetch 
    @u = User.find_by_facebook_id(user.id) 
    if @u.nil? 
     @u = User.find_or_create_by_facebook_id(user.id) 
     @u.update_attributes(:first_name => current_facebook_user.first_name, 
         :last_name => current_facebook_user.last_name) 
     gflash :notice => "Welcome, #{current_facebook_user.name} " 
    else 
     gflash :notice => "Welcome back, #{current_facebook_user.first_name} #{current_facebook_user.last_name}" 
    end 
    return 

    rescue Exception 
     logger.info "Problem" 
     logger.error($!) 
     top_redirect_to auth_url 
    end 

def show 
end 

    def edit 
    user = current_facebook_user.fetch 
    @user = User.find_all_by_facebook_id(user.id) 
    end 

    def update 
    user = current_facebook_user.fetch 
    @user = User.find_all_by_facebook_id(user.id) 
    if @user.update_attributes(:first_name => params[:first_name], 
          :last_name => params[:last_name]) 
     redirect_to user_path, :notice => t('users.update_success') 
    else 
     render :action => 'edit' 
    end 
    end 

end 

========================================== =================

メニューは本当にうまく作成されています。しかし、編集ユーザーをクリックすると、エラーが表示されます。

ActionView::Template::Error (No route matches {:action=>"show", :controller=>"users"}): 

誰かが私に助けてくれますか?誰かがroutes.rbリソースのユーザーがコレクションの代わりに働いていない理由を説明できますか?

ありがとうございます。

答えて

0

showルートを定義する方法が原因です。

resources :users do 
    collection do 
     get :index 
     get :edit 
     post :update 
     get :show #this is your problem 
    end 
end 

この名前を別の操作に変更しようとしています。デフォルトのshowルートがオーバーライドされています。

resources :users do 
    collection do 
     get :index 
     get :edit 
     post :update 
     get :second_show # of course rename this to a better name 
    end 
end 
+0

ご回答ありがとうございます。しかし、私はまだ同じ問題があります。私はあなたの提案をしましたが、まだ:2011-06-27T03:10:19 + 00:00 app [web.1]:ActionView :: Template :: Error(ルートが一致しません{:action => "show"、:controller => "users"})): – glarkou

+0

このパス '<%= link_to user.name、user%>'を試して、 'user'がビューのローカル変数であることを確認できますか?<%= link_to @ user.name 、@user%> 'のいずれかになりますが、ユーザーオブジェクトにアクセスできます。 – s84

+0

リンクの生成方法を投稿できますか? – s84

関連する問題