开发者

find_by_field not working properly in ActiveRecord

I have a navigation system that provides a permalink for any link setup.

When i run the line through script/console this is what it returns:

>> 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>

When i put into my app i get this:

ActiveRecord::RecordNotFound in NavigationsController#permalink

 Couldn't find Navigation without an ID

My Request was "/permalink/gems" and the associated route is:

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

The Controller code that handles that request is:

def permalink
    @nav=Navigation.find_by_pe开发者_如何学编程rmalink(params[:permalink])
    redirect_to :controller => @nav.destination_controller, :action => @nav.destination_action, :id => @nav.destination_id
end

Anyone know why this is happening?


The Problem was caused by Declarative Authorization. It was using the permalink action RESTfully so my navigation find wasnt being used.

To disable Declarative Authorization for all actions bar the RESTful ones in a controller chage:

filter_resource_access

to:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜