我收到此错误: 没有路线匹配{:action =>“new_goal”,:method =>“get”,:controller =>“home”}
<%= form_tag(:action =>"new_goal", :method => "get") do %>
<%= select_tag "deadline-type", "<option>before I turn</option><option>before</option>".html_safe%>
<%= submit_tag "Let's do this!", :name => nil, :class => "radius black button" %>
<% end %>
我将家庭控制器指定为routes.rb中的资源
resources :home, :controller => "home"
更新:当我将其更改为此时,它仍然有效,但我仍然不明白为什么以前的方法不起作用 -
<%= form_tag("/new_goal", :method => "get") do %>
并将其添加到路线:
match '/new_goal', :controller => 'home', :action => 'new_goal'
答案 0 :(得分:1)
您的路线中没有动作new_goal,考虑到资源只定义索引,显示创建,更新和删除。如果您使用的是rails 3
resources :home, :controller => "home" do
get :new_goal
end
如果是铁轨2
resources :home, :controller => "home", :member => { :new_goal => :get}
答案 1 :(得分:0)
你对form_tag
的论点含糊不清,因为你不会关闭哈希。
<%= form_tag({ :action =>"new_goal" }, :method => "get") do %>
Rails尝试使用method
作为URL查找的参数。