0

I have:

- [ 'here now', 'trip scheduled', 'planning a trip', 'already visited' ].each do |travel|
  %div.field.radio.small.snug.bind                  
    = f.radio_button :expected_travel, travel
    = label_tag "visitors_guide_request_expected_travel[#{travel}]", travel.titleize 

I need to have the radio button generated for 'here now' to be checked by default. What's the simplest way to do this?

1 Answer 1

1

you can pass in the :checked option to your radio_button:

= f.radio_button :expected_travel, travel, :checked => travel == 'here now'

That will check the button whose value is here now

Sign up to request clarification or add additional context in comments.

3 Comments

Rails is throwing a syntax error: syntax error, unexpected ':', expecting '}'
I'm using ruby1.9+ hash syntax, maybe you're on an older ruby. Change the checked part to this: :checked => travel == 'here now'. I edited the answer with this.
That worked! This site is a mess. I took over for someone else and it has not been maintained well at all. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.