Strange view problem

I’m working with a Struct that I mapped from a raw sql query for a
report. I finally get the search page to work and display my results,
however the view when rendered not only displays the expected output;
it also shows the Struct as it would look in the rails console!

my view is as follows:

<%=form_tag request.path,:method=>‘get’ do%>
<%=select_tag
‘advisors’,options_from_collection_for_select(@advisors,“id”,“full_name”)
%>
<%=submit_tag “Search”,:name=>nil%>
<%end%>

<%[email protected]_students.each do |student| %>
<%= render :partial => ‘assigned_student’,:collection=>student %>
<%end%>

The partial is as follows:

<%if @assigned_students.kind_of?(Array)%>
<%[email protected]_students.each do |f|%>

<%=f.student_name%>

<%=f.advisor%>

<%=f.semester%>

<%end%>
<%else%>

<%[email protected]_students.student_name%>

<%[email protected]_students.advisor%>

<%[email protected]_students.semester%>>

<%end%>

The relevant controller code is as follows: (I’ve removed the sql
query string itself for readability.)

AdvisorList=Struct.new(:student_name,:advisor,:semester)
def advisor_list
@advisors=Advisors.all

#get_results
respond_to do |format|
format.html
unless params[:advisors].nil?
#long query removed from here
@assigned_students=query.map{|m|AdvisorList.new(m[“Student
Name”],m[“Advisor”],m[“Semester”])
}
format.html
end #end respond_to
end #ends unless
end # ends method

Does anyone here understand what could be the problem?

I’ve had this before, too. But not so recently that I readily remember
what was wrong. Cobwebs suggest it was not much more than a syntax
error.

In your controller you have a close brace but no open brace, which
causes my eye to notice that you also have two format.html calls. Is
there something else missing, or could that be the issue?

On 23 May 2011 05:33, Kevin [email protected] wrote:

<%if @assigned_students.kind_of?(Array)%>
<%[email protected]_students.each do |f|%>

Take the “=” out of the front of the .each call.

Removing the entire loop from the calling view seems to have solved
the issue. Thanks everyone.

@Jim I was trying to have the partial render on the same page that the
search was being done on to see whether the output was different on
that page. That code is such a dirty hack as it stands right now.

On 23 May 2011 05:33, Kevin [email protected] wrote:

I’m working with a Struct that I mapped from a raw sql query for a
report. I finally get the search page to work and display my results,
however the view when rendered not only displays the expected output;
it also shows the Struct as it would look in the rails console!

Try removing stuff from your view until the unexpected output
disappears, then you will know which line of code is showing the
unwanted output. I hope you are using a Source Control System such as
git so that you can easily get back to where you started.

Colin

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs