rails3, clean url, friendly_id, sessions

痴心易碎 提交于 2019-12-11 10:32:15

问题


I'm using friendly_id it works wonderful I add a new private action to my events controller to make sure only events owner can update their events...my show and delete action works fine but when I do an update I get an error

ActiveRecord::RecordNotFound in EventsController#edit Couldn't find User with ID=snow-board

any suggestions to fix this ?

## Events controller
..scaffold generated code
private

 def correct_user
   @user = User.find(params[:id])
      redirect_to(:controller =>'events', :action => 'edit',:id => session[:user_id]) unless current_user?(@user)
 end

## Event view
 link_to 'Edit', edit_event_path(event) 

## Even Model

has_friendly_id :name, :use_slug => true
...validation code

## Session Helper

def current_user=(user)
    @current_user = user
end

回答1:


Does this work (use from_param and not find)?

 def correct_user
   @user = User.from_param(params[:id])


来源:https://stackoverflow.com/questions/6461814/rails3-clean-url-friendly-id-sessions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!