Warning: I am as green as #00FF00 with rails
I have an rhtml view that shows a survey: /views/survey/show.rhtml. I
have a Survey model, helper and controller. I’m using the
acts_as_commentable plugin to collect comments, and trying to save
user comments from users who have taken a survey (don’t ask – it’s
just a test).
To save the comment, I need the id of the survey, which I have when I
show the page originally (but which is gone when the user hits the
submit button to save their comment. So I am just trying to save the
survey id in a hidden field associated with the form.
In the show.rhtml, I have:
<% form_for :comment, @survey, :url => { :action => :save_comment }
do |form| %>
<%= form.hidden_field “survey”, “#{@survey.id}” %>
…
<% end %>
Which results in “ActionView::TemplateError (undefined method `merge’
for “1”:String)”. 1 is the id of the survey, so I am close. I tried
numerous variations of passing values via form_for to a hidden field.
Question 1: How to pass the value so I can get at it when the user
hits submit
In the survey_controller.rb I have
def save_comment
@comment = Comment.new(params[:comment])
logger << “COMMENT #{@comment.comment}\n”
# @survey = Survey.find(???) # somehow I need to get that
survey id so I can do the next line
@survey.add_comment(@comment)
end
Question 2: what magic do I need to get at the value in the hidden
field?
Like I said, I am a noob.
Thanks for your tolerance of my ignorance.
Tom