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