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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:47:37+00:00 2026-05-20T15:47:37+00:00

(NOTE: I have read http://shiningthrough.co.uk/Select-helper-methods-in-Ruby-on-Rails , but still don’t know what to pick) I

  • 0

(NOTE: I have read http://shiningthrough.co.uk/Select-helper-methods-in-Ruby-on-Rails, but still don’t know what to pick)

I have a form that will be used as a search filter (The method is get).

<%= form_tag(reports_courses_allocated_path, :method =>'get') %>
<%= collection_select(:course, :id, @courses, :id, :title, :include_blank => "All Courses") %>
</form>

The above produces the output I want for the tags, but there is no “selected” parameter where I could pass in a params value. I also don’t like the fact that the name is course[id], I would rather have it named course_id

I could do:

<%= select_tag(:course_id, raw("<option>All Courses</option>") + options_from_collection_for_select(@courses, :id, :title, params[:course_id])) %>

But I don’t like the fact that I am concatenating options, but that might be my best bet.

Any opinions/suggestions?

  • 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-20T15:47:38+00:00Added an answer on May 20, 2026 at 3:47 pm

    Must it be a params value that sets ‘selected’ in your case? The ‘selected’ value for collection_select is based on the value of @course.id — you could make sure that @course represents the one that should be selected.

    As for the name, I would stick with the Rails default even when writing your own HTML. It’s what dictates how the parameters come into your action. If your elements have names course[id], course[name], course[type], etc., the params would be

    { :course => { :id => xx, :name => xx, :type => xx } }
    

    which is convenient because then you can call

    Course.new(params[:course])
    

    Also, you do not need to close your forms with your own HTML form tag. The method form_tag takes a block:

    <%= form_tag('/posts') do -%>
      <div><%= submit_tag 'Save' %></div>
    <% end -%>
    

    And finally… I’ve used select_tag and built up an options list before. It can get ugly but you could build it in methods in the view helper where it doesn’t clutter up your rhtml and where it can be unit tested.

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

Sidebar

Related Questions

I have read on MSDN( see Important note ) that RSACryptoServiceProvider must be disposed.
NOTE: I have solved the majority of this problem but have run into a
So I've searched, and read and have done this successfully before, but am running
I have read and re-read this page, as well as run the samples: http://code.google.com/chrome/extensions/background_pages.html
NOTE: I have a related question here (http://stackoverflow.com/questions/6915055/are-jsf-views-shared-between-users) but that deals with a few
I have read many posts(problems) with IE and jquery posts, but never thought I'd
Note - I have not delved very deeply into Apple's iPhone SDK yet. However,
Note: I have given up on compiling iPhone Apps without a developer certificate for
Note I have completely re-written my original post to better explain the issue I
How do I round larger numbers in php. NOTE: I have aready tried the

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.