开发者

rails, adding file in app/views

开发者 https://www.devze.com 2023-02-03 02:54 出处:网络
I crea开发者_JS百科ted a new file in app/views/students called courses.html.erb Then I try to reference it at app/views/students/show.html.erb:

I crea开发者_JS百科ted a new file in app/views/students called courses.html.erb

Then I try to reference it at app/views/students/show.html.erb:

<%= link_to 'courses', courses_student_path(@student) %>

However I am getting

undefined method `courses_student_path' for #<#:0x1052d1648>

What step did I miss?


Note that you never link to views. It is always some action in some controller which in turn renders that view. In this case your action is courses in students controller and you need to create a route for it.

Assuming you already had :students resource defined in config/routes.rb:

resources :students do
  get 'courses', :on => :member
end

This will give you urls like students/1/courses and route helpers courses_student_path and courses_student_url.

http://guides.rubyonrails.org/routing.html#adding-more-restful-actions

0

精彩评论

暂无评论...
验证码 换一张
取 消