不知道这是否以前已经回答过。

为用户提供自定义路线。如果我直接访问用户 /用户 /5,一切都起作用。如果我尝试 /profile甚至 /偶数 /users /current_user具有声明授权,我将获得“没有ID的情况”

map.profile "profile", :controller => "users", :action => "show"
map.edit_profile 'profile/edit', :controller => 'users', :action => 'edit', :conditions => { :method => :get }

我的applicationController具有

tre_filter {| c |授权。current_user= c.current_user}

我的授权_rules有user.id,还尝试了current_user.id。

role :user do
    includes :guest
    has_permission_on :users, :to => [:show, :edit ] do
    if_attribute :id => is { user.id }
  end
end

我究竟做错了什么?

有帮助吗?

解决方案

用于自定义索引类型路由
filter_access_to:all

而不是
filter_resource_access

也得到了我。

其他提示

我使用authlogic,但据我所知,“ current_user”将无法通过路线访问。

如果params [:id] ==“ current_user”(作为字符串),则需要在控制器中检查,然后根据该...进行一些逻辑... IE:

if params[:id] == "current_user"
  @user_id = current_user.id
else
  @user_id = params[:id]
end
@user = User.find(@user_id)

一个非常简单的例子,但它应该说明您将需要从自定义路由获得Current_user的逻辑类型。您也可以将Current_user的命名路由映射到其自己的控制器操作中,但这不是很静止,并且[很可能]您已经拥有的重复功能。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top