的routes.rb
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_controller
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 :(得分: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