通過「使用rails 4.0進行敏捷web開發」學習RoR,並在本地化選擇器(第15.4章)中遇到問題。沒有路由匹配[POST]「/ store/index」
在〜/應用/視圖/佈局/ application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Pragprog Books Online Store</title>
<%= stylesheet_link_tag "application", media: "all",
"data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
</head>
<body class="<%= controller.controller_name %>">
<div id="banner">
<%= form_tag store_index_path, class: 'locale' do %>
<%= select_tag 'set_locale',
options_for_select(LANGUAGES, I18n.locale.to_s),
onchange: 'this.form.submit()' %>
<%= submit_tag 'submit' %>
<%= javascript_tag "$('.locale input').hide()" %>
<% end %>
<%= image_tag("logo.png") %>
<%= @page_title || t('.title') %>
</div>
<div id="columns">
<div id="side">
<% if @cart %>
<%= hidden_div_if(@cart.line_items.empty?, id: 'cart') do %>
<%= render @cart %>
<% end %>
<% end %>
<ul>
<li><a href="http://www...."><%= t('.home') %></a></li>
<li><a href="http://www..../faq"><%= t('.questions') %></a></li>
<li><a href="http://www..../news"><%= t('.news') %></a></li>
<li><a href="http://www..../contact"><%= t('.contact') %></a></li>
</ul>
<% if session[:user_id] %>
<ul>
<li><%= link_to 'Orders', orders_path %></li>
<li><%= link_to 'Products', products_path %></li>
<li><%= link_to 'Users', users_path %></li>
</ul>
<%= button_to 'Logout', logout_path, method: :delete %>
<% end %>
</div>
<div id="main">
<%= yield %>
</div>
</div>
</body>
</html>
在〜/應用程序/控制器/ store_controller.rb
class StoreController < ApplicationController
skip_before_action :authorize
include CurrentCart
before_action :set_cart
def index
if params[:set_locale]
redirect_to store_index_url(locale: params[:set_locale])
else
@products = Product.order(:title)
end
end
end
當我從選擇器中選擇的區域設置,我有一個路由錯誤:沒有路由匹配[POST]「/ store/index」
請幫忙。在GitHub上
全部項目:https://github.com/hronny/depot
問題可能與POST ...索引操作通常是GET –