本文介绍了rails3,干净的 url,friendly_id,会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用friendly_id它工作得很好我向我的事件控制器添加了一个新的私有操作以确保只有事件所有者可以更新他们的事件...我的显示和删除操作工作正常但是当我进行更新时我得到一个错误

ActiveRecord::RecordNotFound in EventsController#edit找不到 ID=snow-board

的用户

有什么建议可以解决这个问题吗?

## 事件控制器..scaffold 生成的代码私人的定义正确_用户@user = User.find(params[:id])redirect_to(:controller =>'events', :action => 'edit',:id => session[:user_id]) 除非 current_user?(@user)结尾## 事件视图link_to '编辑', edit_event_path(event)##偶数模型has_friendly_id :name, :use_slug => true...验证码## 会话助手def current_user=(用户)@current_user = 用户结尾
解决方案

这有效吗(使用 from_param 而不是 find)?

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

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#editCouldn'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
解决方案

Does this work (use from_param and not find)?

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

这篇关于rails3,干净的 url,friendly_id,会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 02:48