I am a little stuck with getting an sql result into my page. I want to
run a select distinct that returns all of the different sections
available and displays this as a form select. In my controller I have:
@resource = Resource.find(params[:id])
@sections = Resource.find_by_sql “SELECT DISTINCT
resources.section FROM resources”
And then in my view I have:
<% for option in @sections %>
<option value="<%= section.section %>"
<%= ’ selected’ if option.section == @resource.section %>>
<%= option.section %>
<% end %>
When I run this I get the following error:
You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.each
From what I can see I am doing the same as other examples. I have run
the SQL on its own to make sure it returns a result and it does.