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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:04:20+00:00 2026-05-30T23:04:20+00:00

I have an action that renders a view which contains this: <select id =’dynamic_select’>

  • 0

I have an action that renders a view which contains this:

<select id ='dynamic_select'>
  <option value = "<%= activity_path %>">All</option>
  <option value = "<%= activity_path(:type => 'enrolled') %>">Enrolled</option>
  <option value = "<%= activity_path(:type => 'redeem') %>">Redeem</option>
  <option value = "<%= activity_path(:type => 'social') %>">Social</option>
</select>

What would be the correct/Rails way of rendering that select and mark as selected one of the options depending on the type parameter:
If there is no type parameter, select “All” options, if there is type=enrolled parameter select Enrolled option, and so on…

I have managed to do that client side with Javascript, but I am wondering what would be the Rails way of doing so.

Rendered HTML:

<select id="dynamic_select" name="dynamic_select">
<option value="/activity">All</option>
<option value="/activity?type=enrolled">Enrolled</option>
<option value="/activity?type=redeem">Redeem</option>
<option value="/activity?type=social">Social</option>
</select>
  • 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-30T23:04:21+00:00Added an answer on May 30, 2026 at 11:04 pm

    Something like the following. I have displayed the select_options here, but you should probably generate them in your controller and pass them through to the view.

    The key is using options_for_select.

    <% select_options = {"All" => activity_path} %>
    <% %w{Enrolled Redeem Social}.each {|opt| select_options[opt] = activity_path(:type => opt.downcase)} %>
    <% form_for(resource) do |f| %>
      <%= s.select :dynamic, options_for_select(select_option, :selected => select_options[@default || "All"]) %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an action that renders two different view scripts based on whether the
I have this div in my rails view which renders a collection of users:
I have a controller action which renders a partial view: public ActionResult Details(int id)
Im not sure if I'm doing this right. I have an action that I
I have a form action that needs to have its value set from a
I have a controller action that checks this.User.Identity.IsAuthenticated What do you suggest how to
I have a really simple action in a controller that simply returns a view
I have a complex view model which contains a collection of other objects which
I have a g:select in my view that displays a list of products: <g:form
I have a controller's method which renders a template. This works fine to render

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.