Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8457317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:46:52+00:00 2026-06-10T12:46:52+00:00

This is my first question on SO. W00t! As in this railscast , I’m

  • 0

This is my first question on SO. W00t!

As in this railscast, I’m able to create a survey model and form which accepts accepts_nested_attributes_for questions, and the questions model accepts_nested_attributes_for answers.

If users are signed in, then I can associate their answers with their user_id. However, I’d like to make it possible for guests to fill out this form too. This would be a great way to lower the barrier to participation.

I’d like guest users to be able to add their name to the form so other users can distinguish between guests that have not yet created accounts. To do that, I’ve created a guest_name field in the answer model.

The problem: If they add their name to the form after they create new answers, how can I associate their name with their answer?

Inside surveys_controller.rb I am currently creating a variable called @responding_user_id and setting it to the signed-in user’s ID or setting it to 0 if no one is signed in:

@responding_user_id = (current_user ? current_user.id : 0)

so that inside answer.html.erb, I can do this to associate the signed-in user’s ID with his/her answer:

<%= f.hidden_field :user_id, :value => @responding_user_id %>

In the survey, users see multiple questions and they can add one or more answers to any question by clicking the “Add Answer” link from the partial called _question_fields.html.erb:

<%= f.fields_for :answers do |builder| %>
<%= render 'answer_fields', f: builder %>
<% end %>
<%= link_to_add_fields "Add a New Response", f, :answers %>

I guess I could force them to input their name prior to adding answers and then change the hidden user_id fields through jQuery, but that is not an optimal user experience.

The only part of this that I’m having trouble with is assigning the guest name to the answer’s hidden user_id field. The reason this is difficult is that the HTML for the hidden field is generated when the user clicks “Add Answer” and at that point, they may not have entered their guest name yet.

Maybe the only way to do this is with jQuery as mentioned above?

Thanks!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:46:53+00:00Added an answer on June 10, 2026 at 12:46 pm

    First of all, here do you suppose to store the guest’s names? You have just a user_id field. so you have to change your model.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first question I have searched for any launching activity questions and
This is my first question on stackoverflow (I have usually been able to figure
this is my first question in here, and I would like to ask if
This is my first question on Stack Overflow, so I hope that I'm clear
This is my first question, so please be gentle. I'm trying out Apache Camel
this is my first question to SO so i'll try not to disgrace myself.
this is my first question here so be gentle ! recently i try to
this is my first question on stack overflow. Some quick background, this is not
This is my first question, but I've already found this site extremely helpful, so
This is my first question in this forum, so i hope to be clear:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.