[英]Ruby on Rails - how to correctly map and link to a new controller?
I am trying to create this controller: 我正在尝试创建此控制器:
def calculate
# Do some calculations here
respond_to do |format|
format.json{head status}
end
end
and I have a HAML file in which I make my HTML and in there I want to link to something like this: 我有一个HAML文件,我在其中制作我的HTML,在那里我想链接到这样的东西:
=link_to("stats" , controller_path_url)
where controller_path is a rake routes path that is shown. 其中controller_path是显示的rake路径路径。 My question is how do I make this sort of uniquely named controller function to be mapped and show its path when I do rake routes?
我的问题是如何将这种唯一命名的控制器函数映射并在我耙路线时显示其路径? Is there something I have to do in routes.rb?
在routes.rb中我有什么需要做的吗? What should I change there?
我应该在那里改变什么?
Thanks! 谢谢!
You should do smth like following in your routes.rb
file: 你应该在你的
routes.rb
文件中做如下的smth:
match 'calculate' => 'controller_name#calculate'
匹配'calculate'=>'controller_name#calculate'
then run: 然后运行:
bundle exec rake routes
捆绑exec rake路线
and see your path. 并看到你的道路。
It should be calculcate_path
for path and calculate_url
for full path. 它应该是
calculcate_path
for path和calculate_url
for full path。
You'll need to modify your routes.rb file. 您需要修改routes.rb文件。 I suggest you check out http://guides.rubyonrails.org/routing.html , it's really extremely helpful.
我建议你查看http://guides.rubyonrails.org/routing.html ,它真的非常有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.