我是Ruby的新手,在按照以下教程完成我的第一个个人项目后,我遇到了一些问题:http://guides.rubyonrails.org/getting_started.html
我正在尝试在欢迎页面上创建一个指向我的storevalue视图的链接,如下所示:
index.html.erb:
<h1>Welcome#index</h1>
<%= link_to 'form page', controller: 'storevalue' %>
抛出此错误:
No route matches {:action=>"index", :controller=>"storevalue_path"}
为什么ruby会尝试动作索引?我是否需要修复我的routes.rb以引用storevalue / new而不是storevalue / index(这似乎是试图引用)?如果是这样,我该怎么做,因为我不能在路由中创建两个根(根据另一个错误消息)
routes.rb中:
Rails.application.routes.draw do
get 'welcome/index'
root 'welcome#index'
get 'storevalue/new'
resource :storevalue
end
答案 0 :(得分:2)
我相信您正在尝试使用创建商店值表单。
您的代码应为
<%= link_to 'form page', controller: 'storevalue', action: 'new' %>
答案 1 :(得分:1)
如果您未指定操作,则rails会假定需要查找&#39;索引&#39; &#39; storevalue_path&#39;中的操作控制器。
潜在的解决方案:
action:=>"index"
希望这有帮助。