Mel Mel - 2 months ago 6x
Ruby Question

Rails - how to write an index view?

I'm having trouble figuring out how to display an index.

In my organisation requests view folder, I have a file called index.html.erb.

In that file, I'm trying to list each organisation request. I've tried each of the following formulations:

<% OrganisationRequest.each do |OrgReq| %>
<% organisation_request.each do |OrgReq| %>
<% @organisation_request.each do |OrgReq| %>
<% @organisation_requests.each do |OrgReq| %>

In each case, I get an error that says:

formal argument cannot be a constant

I thought a constant meant something beginning with a capital letter. 3 of the above attempts don't begin with a capital letter.

It's also confusing to me since in my user index, I have <% User.each %> and I don't get an error message.

Can anyone see what's gone wrong? How do I ask for a list of objects?


If you have your data and view right, you should be able to fix with:

<% @organisation_requests.each do |org_req| %>
<% end %>