Rails控制器/路由问题
我是 RoR 新手,我无法让我的死记硬背之一发挥作用,不确定发生了什么?我已经在我的routes.rb 文件中定义了一条路线,像这样...
map.connect 'myurl/:someid/:start/:limit', :conditions => { :method => :get }, :controller => 'mycontroller', :action => 'get_data_list'
# method defintion in mycontroller
def get_data_list (someid, start, limit)
render :text => "Blah"
end
我使用以下网址来调用上述路线,但它不起作用?有什么线索吗? http://host:port/myurl/24/1/10
它给出了以下错误。看起来它达到了控制器操作,但之后失败了?
处理 Mycontroller#get_data_list (对于 127.0.0.1,2010-07-12 19:07:45) [GET] 参数:{"start"=="1", “限制”=>“10”,“someid”=>“24”}
ArgumentError(参数数量错误(0 代表 3)):
I am new to RoR and I cant get one of my rotes to work, not sure whats going on? I have defined a route in my routes.rb file, somthing like this...
map.connect 'myurl/:someid/:start/:limit', :conditions => { :method => :get }, :controller => 'mycontroller', :action => 'get_data_list'
# method defintion in mycontroller
def get_data_list (someid, start, limit)
render :text => "Blah"
end
And I am using the following the url to invoke the above route and it does not work? Any clue?
http://host:port/myurl/24/1/10
It gives the following error. Looks its reached the controller action, but fails after that??
Processing Mycontroller#get_data_list
(for 127.0.0.1 at 2010-07-12 19:07:45)
[GET] Parameters: {"start"=>"1",
"limit"=>"10", "someid"=>"24"}ArgumentError (wrong number of arguments (0 for 3)):
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是你想要的:
This is what you want:
您不需要控制器中方法的 (someid, start, limit) 部分。这些变量由 params[:someid] 根据您的路线进行访问。 ArgumentError 是因为控制器方法需要未传递给它的变量。
You don't need the (someid, start, limit) part of the method in your controller. Those variables are accesses by params[:someid], based on your route. The ArgumentError is because the controller method is expecting variables that aren't being passed to it.