Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Edit the question to include
desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem
. This will help others answer the question.
Closed
8 years ago
.
In my ruby on rails application, I have a controller
hiring
and in the
view
tree
hiring
controller have one page
new
and I add another page called
viewhiring
also
and I have added two tabs in both
hiring
and
new
page i.e below:
<div id="nave">
<ul id="menu">
<li class="sub"><a href="/hiring/viewhiring">View Hiring</a>
<li class="sub"><a href="<%= templates_path %>">Hiring</a> //new page that I call hiring
And I want to redirect from Hiring
page to 'View Hiring' page using anchor <a href="/hiring/viewhiring">View Hiring</a>
but its not working.
kindly help me, waiting for reply.
Thanks.
–
–
Helpers
You should read up about Rails URL helpers - you shouldn't be using <a href="">
in your view files, you can use <% link_to %>
instead (as pointed out by @deepti Kakade
):
<%= link_to "Hiring", templates_path %>
You really need to use all the rails
helpers (there are many more than just link_to
) in place of your HTML because they firstly help you keep your code DRY, but secondly ensure you're keeping up with the latest Rails developments
One of the main benefits of using a framework such as Rails is that it gives you the ability to focus on creating an amazing system, rather than worrying about small coding complications
Routes
Secondly, you have to consider your routes
#config/routes.rb
resources :hiring #-> hiring_path / domain.com/hiring/index
Rails' routing uses a resourceful
structure - meaning it allows you to build a set of routes around "resources" in your application. Simply, "resources" are your controllers; but they're really your individual data records:
In this sense, you should look at which path
you're using, as it will correspond directly to your routes
Use link_to, it generates the anchor tag of html, for example
<%= link_to "linktext", action_path %>
your action_path is nothing but the href.
<div id="nave">
<ul id="menu">
<li class="sub"> <%= link_to 'View Hiring', hiring_viewhiring_path %></li>
<li class="sub"><%= link_to 'Hiring', templates_path %></li> //new page that I call hiring
Hope it helps .
'View Hiring'= is the name posted .
hiring_viewhiring_path = is the path
eg. welcome_index_path
this path is in \app/views/welcome/index.html
Did you get it ?