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

  • Home
  • SEARCH
  • 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 6252749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:51:47+00:00 2026-05-24T13:51:47+00:00

Im very new to programming with ruby on rails. I need to write a

  • 0

Im very new to programming with ruby on rails.

I need to write a method for changed default values in a text_field.
It should look something like this:

count = 0
def value()
{
  count++
  value = ""
  if count == 1
    value = "Pre-Sales"
  elsif count == 2
    value = "Project"
  etc...
  end
  return value
}
end

this should mean that everytime the method is run then the count goes up by 1.
im calling the method here:

<p class="fields">
    <%= f.label :task_name, "Task Name" %>
    <%= f.text_field :task_name, :value => value %>
    <%= link_to_remove_fields "remove", f %>
</p>

its inside a partial too…
I know im missing alot here and need someone to help.

  • 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-05-24T13:51:48+00:00Added an answer on May 24, 2026 at 1:51 pm

    I got a feeling that you’re doing something crazy / “not Rails way”.

    Ok, so you enter a page and your form is rendered. I guess you’re using form_for helper and a :task_name is a field in db related to some model right?
    What’s the reasoning behind having :

     <%= f.text_field :task_name, :value => translated_1 %>
     <%= f.text_field :task_name, :value => translated_2 %>
     <%= f.text_field :task_name, :value => translated_3 %>
     <%= f.text_field :task_name, :value => translated_4 %>
     <%= f.text_field :task_name, :value => translated_5 %>
    

    ?

    I don’t understand it but let’s say you have your paragraph in a partial. You could do:

    5.times do |i|
      render :partial => "this_is_crazy", :locals => {:i => i, :f => f}
    end
    

    and then inside this partial you would have your:

    <p class="fields">
        <%= f.label :task_name, "Task Name" %>
        <%= f.text_field :task_name, :value => get_default_value(i) %>
        <%= link_to_remove_fields "remove", f %>
    </p>
    

    then you would define your get_default_value(i) in “helpers/crazy_helper.rb” using a case or bunch of ifs… (that’s a possibility, not a suggestion or the way I would do it)

    But again, I got a feeling that you’re doing something wrong… Maybe I you post something more about your problem, I will be able to get you back on the right track 🙂

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

Sidebar

Related Questions

I'm very new to programming and I am trying to write a program that
I'm very new to programming and I must be missing something here. The first
I'm very new to programming, and I'd like to write a Windows Application. So
I'm very new in programming. I'm writing a PHP application that need to execute
I'm still very new to programming and I want to write the cleanest code
I'm very much new to programming and have been doing fairly well so far.
I am very new to C++ programming and you will see why. I want
I am very new at C programming and I am working on a firmware
I am very new at all this c# Windows Phone programming, so this is
First off I am very new to Objective C and iPhone programming. Now that

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.