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 8933203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:29:01+00:00 2026-06-15T09:29:01+00:00

When using the form_for helper with an html.erb page, alot of the work is

  • 0

When using the form_for helper with an html.erb page, alot of the work is abstracted for you, so something like

f.label :book

gets turned into an html label. I want to fill in a text field with a string, so that I can take the values associated with several symbols, form them into a string, and put that string into the :value key.

<%= form_for(@backpack) do |f| %>
  <ul>
    <% @backpack.errors.full_messages.each do |error| %>
        <li><%= error %></li>
    <% end %>
  </ul>
  <p>
    <%= f.label :calculator %><br/>
    <%= f.text_field :calculator %>
  </p>
  <p>
    <%= f.label :lunchbox %><br/>
    <%= f.text_field :lunchbox %>
  </p>
    <%= f.label :books %><br/>
  </p>
    <%= f.fields_for :books do |g| %>
      <p>
        <%= g.text_field :book, :value => MY_STRING %>
      </p>
    <% end %>
  </p>
  <p>
    <%= f.submit %>
  </p>
<% end %>

MY_STRING = :title by :author

So, if I left g.text_field alone with :book, it would automatically fill in the string associated with that symbol. How can I implement that in my custom way? How exactly do symbols reference the actual data in my nested form?

I should also mention I have the

accepts_nested_attributes_for :books

attribute in my backpack controller, so I have access to the second model/database

  • 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-15T09:29:03+00:00Added an answer on June 15, 2026 at 9:29 am

    A symbol is just a symbol. No direct connection to the object. But you can use the book object attached to the form builder to create a string describing the book:

    <%= g.text_field :book, :value => "#{g.object.title} by #{g.object.author}" %>
    

    Even better, you can write a helper to handle this for you:

    # in backpacks_helper.rb
    def book_title(book)
      "#{book.title} by #{book.author}"
    end
    

    And use it like so:

    <%= g.text_field :book, :value => book_title(g.object) %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I feel like im missing something simple here. I am using the form_for helper
Is it possible to specify html attributes while using the form_for helper methods? For
I'm using a form_for helper with the bootstrap framework. When I use date_select it
I am creating a select box for a form using this in _form.html.erb <%=
I'm trying to generate a form using the form_for helper in RoR but I
Typically I'm ok with the auto-generated form element names when using the HTML helper
Ordinarily, using form_for(@foo) means that on the back end of the form's action, you'll
I am trying to save a model named 'customer' using form_for tag. I do
I'm using TinyMCE as the editor for creating an HTML form for people to
Hi trying to make a Registration page with Ruby on rails using the tutorial

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.