I’m creating a report system which uses a meta question model to create the reports. Basically i have a table with a number of questions like the following:
variables table:
id | name | variable_type | description | breakpoint | time_frequency
Now the system builds the report question depending on things like the time frequency of the report.
Now i have two tables in order to save the reports:
report_bodies table:
variable_id | report_id | value
report_heads table
id | email | name
With this approch i need to create the report and then use that id to save the answers to the questions of that report.
I have done an after_filter in the report_heads controller to somehow pass the next function the just created id.
after_filter :go_to_report, :only => :create
finally my empty go_to_report function
def go_to_report
#what to do here?
end
Thank you in advance.
Update
So, i discovered that i could call the new function of the report_bodies directly from the creation of the report_head with this:
format.html { redirect_to :new_report_body, notice: 'Report head was successfully created.', :parameter => @report_head.id }
And the the new function for report_bodies is:
def new
@report_head_id = :parameter
@report_questions = getDailyVariables
@report_body = ReportBody.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @report_body }
end
end
However when the in the view i’m not receiving the id of the report_head but a simple string instead
<!-- code from the view (_form.html.erg): -->
<%= builder.hidden_field :report_id, :value => @report_head_id %>
<!-- rendered view: -->
<input id="report_bodies_report_id" name="report_bodies[report_id]" value="parameter" type="hidden">
It looks like you’re receiving the simple string
"parameter"because you’re setting@report_head_idto a symbol:parameterin yournewaction.In the
newaction, try using@report_head_id = params[:parameter]instead.