a question about routing
i want to read all 开发者_如何学Gorecords of my table . this is my code
Controller:
def list
@vorlesung=Vorlesung.find(:all)
end
View:
<html>
<body>
<table>
<tr>
<th>
Name
</th>
</tr>
<% @vorlesung.each do |v| %>
<tr>
<td><%= v.Name %> </td>
</tr>
<% end %>
</table>
</body>
</html>
and rout file:
root :to => 'vorlesungs#Show'
match 'vorlesungs/new' =>'vorlesungs#new'
match 'vorlesungs' =>'vorlesungs#list'
resources :vorlesungs
as i understood for CRUD i schould write only resources :vorlesungs. but my code doesn't work without match 'vorlesungs' =>'vorlesungs#list' would you please someone tell me that reason?
List is not a default resource created by resources. Check out the table in the link below to see all actions used by routes created with the resources method.
http://guides.rubyonrails.org/routing.html#resources-on-the-web
You should either keep in your route or rename list to index (including list.html.erb in your views). I recommend renaming list to index to avoid breaking convention.
The CRUD action for listing all the elements of a resource is index so if you change your code to
def index
@vorlesung=Vorlesung.find(:all)
end
And rename your view to index then you will be able to use
resources :vorlesung
精彩评论