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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:07:23+00:00 2026-06-14T13:07:23+00:00

I can’t find how to display a dynamic label in Rails, i’ve tried using

  • 0

I can’t find how to display a dynamic label in Rails, i’ve tried using the :value => show_name property but it didn’t work, it only displays Show name. Here is the view code

<p>
   <div class="control-group">
           <%= f.label :show_name, :value => :show_name, :class => 'control-label' %> 
           <%= #this next line fails with undefined method `show_name' for #<ActionView::Helpers::FormBuiler>
              #f.label f.send :show_name, :class => 'control-label'
           %> 
       <div class="controls">
           <%= f.text_field :variable_value, :class => 'text_field' %> 
           <%= f.hidden_field :variable_id, :class => 'text_field' %> 
       <%= f.hidden_field :show_name, :class => 'text_field' %> 
       </div>
   </div>
<p>

and if needed here is the show_name definition inside my model.

  def show_name
    Variable.find_by_id(self.variable_id).name
  end
  • 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-14T13:07:24+00:00Added an answer on June 14, 2026 at 1:07 pm

    Ok, so i end up finding a solution that is very DRY, thank to this post. And the only thing im going to do is explain a lit bit more what to do:

    First we are going to asume the most complex case in which we have nested forms and so we are using fields_for inside a form_for method:

      <!-- f represents the form from `form_for` -->
      <%= f.fields_for :nested_model do |builder| %>
        <p>
          <div class="control-group">
    
             <!-- here we are just calling a helper method to get things DRY -->
    
             <%= builder.label return_value_of_symbol(builder,:show_name), :class => 'control-label' %> 
             <div class="controls">
                <%= builder.text_field :variable_value, :class => 'text_field' %> 
                <%= builder.hidden_field :variable_id, :class => 'text_field' %> 
             </div>
          </div>
        </p>
      <% end %>
    

    Note that we included the builder object(as specified in the fields_for call) in the parameters of our helper.

    In our helper we define the return_value_of_symbol function

      def return_value_of_symbol(obj,sym)
        # And here is the magic, we need to call the object method of fields_for
        # to obtain the reference of the object we are building for, then call the
        # send function so we send a message with the actual value of the symbol 
        # and so we return that message to our view.  
        obj.object.send(sym)
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone help me trying to find out why this doesn't work. The brushes
Can anyone let me know how can we change the value of kendo combobox
Can I authenticate with just Google account username and password instead of using OAuth?
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Can PHP PDO extension bind nested objects automatically ? I mean using foreign key
Can anybody tell me a regular expression to use within some PHP to find
Can someone please explain why this doesn't work? MyClass myClass1 = new MyClass(); object
We're building an app, our first using Rails 3, and we're having to build
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
Can anyone tell me how I can display a status message like 12 seconds

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.