简体   繁体   中英

Move one page to another in Ruby on rails?

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>  

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 %>

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

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 %>
<%= link_to "Link", controller:"controllername" %>

是您应该使用的代码

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