rails, adding file in app/views
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
精彩评论