假设:
以下部分:
<%= form_for @user_session, :url => user_session_path do |f| %>
<%= f.error_messages %>
<span class="field-group">
<div>
<%= f.label :login, "Login Name:" %><br />
<%= f.text_field :login %><br />
</div>
</span>
<div class="clear"></div>
<span class="field-group">
<div>
<%= f.label :password, "Password:" %><br />
<%= f.password_field :password %> <span class="hint">Reminder: Your password is case sensitive.</span><br />
</div>
</span>
<div class="clear"></div>
<span class="field-group">
<div>
<%= f.check_box :remember_me %> <%= f.label :remember_me %>
</div>
</span>
<div class="clear"></div>
<%= f.submit "Login" %>
<% end %>
以下路线:
$ rake routes | grep user_session | grep show
user_session GET /user_session/:id(.:format) {:action=>"show", :controller=>"user_session"}
以下路线配置:
# user session stuff
resources :user_session do
member do
put :forgot_password
put :terms
get :terms
end
end
match '/login', :to => 'user_sessions#new', :as => 'login'
match '/logout', :to => 'user_sessions#destroy', :as => 'logout'
问题:
当我调用使用此部分的页面时,出现以下错误:
ActionController::RoutingError in User_sessions#new
Showing /app/views/edit_shared/_login.html.erb where line #2 raised:
No route matches {:action=>"show", :controller=>"user_session"}
提取的来源(第2行):
1:
2: <%= form_for @user_session, :url => user_session_path do |f| %>
3: <%= f.error_messages %>
4: <span class="field-group">
5: <div>
因此该路线存在,但铁路表示不存在。什么给出了什么?在我开始升级到Rails 3.0.5之前一切正常。
答案 0 :(得分:0)
您的路线只接受GET
次请求。表单默认发送POST
请求。
修改强>
首先,您应该使用您的命名路线而不是user_session_path
:
<%= form_for @user_session, :url => login_path do |f| %>
您想要的操作是create
,而不是new
(显示表单):
match '/login', :to => 'user_sessions#create', :as => 'login'
答案 1 :(得分:0)
尝试从表单中删除:url => user_session_path
。通过指定form_for @user_session
,Rails将查找user_session
RESTful路由并为您生成URL。
答案 2 :(得分:0)
将:url => user_session_path
更改为:url => {:action => :create}
就可以了。