In Rails 3, using the new respond_to and respond_with constructs, I do this:
class SurveysController < ApplicationController
respond_to :html
def survey
@program_id = params[:program_id]
@participant_id = params[:participant_id]
respond_with [@program_id, @participant_id]
end
end
When the view is displayed (survey.html.erb) the variables program_id, @participant_id are both properly set up. However, if I omit them from the respond_with, as follows:
class SurveysController < ApplicationController
respond_to :html
def survey
@program_id = params[:program_id]
@participant_id = params[:participant_id]
@foo = "foo"
respond_with @foo
end
end
The same two instance variables are still visible in the view. In other words, all instance variables from the action are made available from within the view.
Question: why should I put instance variables on the respond_to line?