简体   繁体   English

清理控制器,今天可以使用Merb风格的动作吗?

[英]Cleaning up my controllers, can I have Merb style action defs today?

In Rail 2.3.2 can I have merb style action definitions: 在Rail 2.3.2中可以有merb样式动作定义:

Eg: instead of 例如:代替

def show
  @user = User.find(params[:id])
end

Can I have: 我能有......吗:

def show(id)
  @user = User.find(id) 
end

What kind of crazy monkey patching do I need to do to get this working, note I only need this working for MRI so ParseTree is an option. 要使此工作正常,我需要执行哪种疯狂的猴子修补操作,请注意,我只需要对MRI进行此工作,因此可以选择ParseTree。

Note: there is a Rails 3 port of this functionality now. 注意:现在有此功能的Rails 3端口

EDIT: I was wrong: Method#parameters has been added to Ruby 1.9.2. 编辑:我错了: Method#parameters已添加到Ruby 1.9.2。


Original: 原版的:

No, this is not possible in Rails. 不,这在Rails中是不可能的。

There is almost zero chance of this making it into Rails 3.0. 使其进入Rails 3.0的可能性几乎为零。 merb-action-args used ParseTree which doesn't and will not work on Ruby 1.9 , therefore making it unlikely that it will be included in Rails. merb-action-args使用的ParseTree 不能也不能在Ruby 1.9上使用 ,因此不太可能将其包含在Rails中。

您可以在before_filter中将所有参数更改为实例var(例如@id)...

我正在运行Rails 2.3.3,而User.find(id)可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM