简体   繁体   中英

ActionController::RoutingError

I am just learning Rails. I had encountered a routing error, though I think I have specified the correct rules in the routing.rb. I have attached the code. Please help

routes.rb

  map.connect ':controller/:action'
  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'

Controller

class EntriesController < ApplicationController
  def sign_in
    @name = params[:visitor_name]
  end
end

View

<html> 
<head><title>Hello <%=h @name %></title></head>
<body> 
<%=h @name %>
<% form_tag :action => 'sign_in' do %>
<p>Enter your name:
<%= text_field_tag 'visitor_name', @name %></p>
<%= submit_tag 'Sign in' %>
<% end %>
</body> 
</html>

Thanks

Your form_tag needs to specify the controller as well as the action. So:

<%= form_tag :controller => 'entries', :action => 'sign_in' do %>

Note that in Rails' terms, this is a very old-fashioned way of doing things and I'd recommend that you learn about RESTful routes within the Rails Routing from the Outside In guide.

You have to include follwing in your routes.rb

map.resources :entries, :collection=>{:sign_in=>:post}

Restart your server

<% form_tag :controller=>'entries' , :action => 'sign_in' do %>

if your view in entries folder only then you need not to specify controller name it will by default take it. just write

<% form_tag :action => 'sign_in' do %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM