Reputation: 878
I am unable to move to the signup page after clicking "Sign Up Now" in home page. I have gone through stack-overflow but none of them solve the problem. Here are my codes:
Routes.rb
get "users/new"
root :to => 'static_pages#home'
match '/static_pages/home', :to => 'static_pages#home'
match '/static_pages/help', :to => 'static_pages#help'
match '/static_pages/about', :to => 'static_pages#about'
match '/static_pages/contact', :to => 'static_pages#contact'
match '/users/new', :to => 'users#new'
home.html.erb
<div class="center hero-unit">
<h1>Welcome to the Sample App</h1>
<h2>
This is the home page for the
<a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
sample application.
</h2>
<%= link_to "Sign up now!", "signup_path", class: "btn btn-large btn-primary" %>
</div>
<%= link_to image_tag("rails.png", alt: "Rails"), 'http://rubyonrails.org/' %>
header.html.erb
<header class="navbar navbar-fixed-top navbar-inverse">
<div class="navbar-inner">
<div class="container">
<%= link_to "sample app", root_path, id: "logo" %>
<nav>
<ul class="nav pull-right">
<li><%= link_to "Home", 'home' %></li>
<li><%= link_to "Help", 'help' %></li>
<li><%= link_to "Sign in", 'new' %></li>
</ul>
</nav>
</div>
</div>
</header>
users_controller.rb
class UsersController < ApplicationController
def new
end
end
I am stuck on this for long and unable to find the solution for this.
Upvotes: 0
Views: 74
Reputation: 4551
I guess you would like to use
match '/users/new', :to => 'users#new'
as the signup
route. You could specify this with the :as
parameter like this:
match '/users/new', :to => 'users#new', :as => 'signup'
which will give you the correct signup_path
.
Note that per the Rails routing docs you should now use get
or post
instead of match
or specify :via => [:post]
to disallow additional query parameters. Btw: your signup
should be a :post
as it attempts to change the state of the server.
Upvotes: 1
Reputation: 878
match '/signup', to: 'users#new'
This worked fine for me and I don't know how I missed that
Upvotes: 1
Reputation: 472
EDIT: Try adding this to your routes.rb
match '/signup', to: 'users#new', via: 'get'
Upvotes: 1