简体   繁体   中英

Adding links to another page in ruby on rails

<a class="info" href="app/views/pages/new_idea.html">Click!!!</a>

This is my code to link to another page from my index page on clicking an option. It worked separately. but after integrating it into rails, its not working. this is the error msg.

No route matches [GET] "/app/views/pages/new_idea.html"

EDIT:

These are the routes:

$ rake routes | grep pages

     root GET    /                         pages#index_student 
    pages GET    /pages(.:format)          pages#index 
          POST   /pages(.:format)          pages#create 
 new_page GET    /pages/new(.:format)      pages#new 
edit_page GET    /pages/:id/edit(.:format) pages#edit 
     page GET    /pages/:id(.:format)      pages#show 
          PATCH  /pages/:id(.:format)      pages#update 
          PUT    /pages/:id(.:format)      pages#update 
          DELETE /pages/:id(.:format)      pages#destroy

You haven't defined route for your new_idea action

Add the following in routes.rb

resources :pages do 
  collection do
    get :new_idea
  end
end

Adding this will give you:

new_idea_pages GET    /pages/new_idea(.:format) pages#new_idea

Then you can use:

<a href="<%= new_idea_pages_path %>">Click!!!</a>

尝试这个,

<a href="<%= new_page_path %>">Click!!!</a>

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