1

In my rails project there is a controller and view named "Welcome/index" where index is an action and another one named "home/page" . As i set root"home#page" as my root page. Now i want to transfer from "page.html.erb" into "index.html.erb" . How can i do that. And the code i written is below.Do i have to enter some thing in my controller class. please suggest. these are the links that i tried. (How to create an anchor and redirect to this specific anchor in Ruby on Rails)

<a rel="nofollow" href="index.html.erb">Transfer to index</a>  
Community
  • 1
  • 1

4 Answers4

2

You are not supposed to link to .html.erb files, you should link to the methods (not exactly the name of the method, but the name of the route) of a controller.

I strongly encourage you to review the ruby on rails MVC principles. You can read about routing and linking aswell.

Responding to your question, check out the command "rake routes". It will list the defined routes of your app and helps you to use them.

Try to replace your code by this:

<%= link_to 'welcome', welcome_path %>
José Barbosa
  • 913
  • 8
  • 17
0

If you want go for index action of Welcome controller then you can use:

<%= link_to "Transfer to index", welcome_path %>

Check the rake routes for path.

Plese refer link

Ram Patidar
  • 666
  • 1
  • 6
  • 16
0

You need to make sure a named route is defined for welcome/index and then can use the Rails helper link_to to automatically build your link for you in the view.

In routes.rb:

match '/welcome' => 'welcome#index', :as => :welcome

In your page.html.erb view:

<%= link_to 'Go to Welcome Page', welcome_path %>
  • It says that i should not use match in the route . this is my route code .. ` Blogz::Application.routes.draw do get "home/page" #root 'welcome#index' get "welcome/index" match '/welcome' => 'welcome#index', :as => :welcome root 'home#page'` – Vignesh Gopalakrishnan Feb 25 '14 at 13:04
0
<%= link_to "Link", controller:"controllername" %>

is the code you should use

John
  • 140
  • 8