代码之家  ›  专栏  ›  技术社区  ›  Arcath

在ActiveRecord中按字段查找未正常工作

  •  0
  • Arcath  · 技术社区  · 16 年前

    我有一个导航系统,可以为任何链接设置提供永久链接。

    当我通过脚本/控制台运行该行时,它返回的结果是:

    >> Navigation.find_by_permalink("gems")
    => #<Navigation id: 10, text: "Gems", parent: nil, destination_controller: "pages", destination_action: "show", destination_id: "1", permalink: "gems", created_at: "2009-12-26 14:56:28", updated_at: "2009-12-26 14:56:28", previous: 9>
    

    当我进入我的应用程序时,我会得到:

    ActiveRecord::RecordNotFound in NavigationsController#permalink
    
     Couldn't find Navigation without an ID
    

    我的请求是“/permalink/gems”,相关路线是:

    map.permalink "permalink/:permalink", :controller => 'navigations', :action => 'permalink'
    

    处理该请求的控制器代码是:

    def permalink
        @nav=Navigation.find_by_permalink(params[:permalink])
        redirect_to :controller => @nav.destination_controller, :action => @nav.destination_action, :id => @nav.destination_id
    end
    

    有人知道这是为什么吗?

    1 回复  |  直到 16 年前
        1
  •  0
  •   Arcath    16 年前

    filter_resource_access
    

    filter_access_to :index, :show, :edit, :new, :create, :update, :destroy