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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:54:31+00:00 2026-05-26T21:54:31+00:00

I have a model, Product, and on the show view for this model, I

  • 0

I have a model, Product, and on the show view for this model, I want to have a select box for the user to be able to view a different Product. So, if a user’s looking at the “Product 1” page, they can select “Product 2” from the select box and view that product.

Here’s the code I’m using to create this select box:

<%= form_tag({:controller => "products", :action => "show"}, :method => :get) do %>
<%= select_tag :product_id, options_from_collection_for_select(Product.all, :id, :title) %>
<%= submit_tag 'Go' %>

But this doesn’t work. I can choose a different product, and click Go, but it just goes to the same product, not the one I selected in the box.

What am I doing wrong here?

Basically, I’m trying to use a select box instead of something like this:

<% Product.all.each do |p| %>
    <%= link_to p.title, p %>
<% end %>

Here’s what I have for my show action in the controller:

@product = Product.find(params[:id])
    rescue ActiveRecord::RecordNotFound
    flash[:alert] = 'The product you were looking for could not be found'
    redirect_to products_path
  • 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-26T21:54:32+00:00Added an answer on May 26, 2026 at 9:54 pm

    well a simple way would be to check if the params[:product_id] was passed by your form, if it is then use that instead of params[:id] basically:

    if params[:product_id]
       @product = Product.find(params[:product_id])
    else
       @product = Product.find(params[:id])
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view model that show a product.. but the price is in
I'm using Doctrine ODM with MongoDB. I have a product model like this: namespace
I have this model var Item = Backbone.Model.extend({ url: 'http://localhost/InterprisePOS/Product/loaditembycategory/Event Materials' }); var onSuccess
I have a view model that contains a Product class type and an IEnumerable<
I have 3 models. These are the User , Product and Price model. I
I have a model Product with a description field. Now I want to have
I'm starting to use Paper Trail gem, I have this Product model: name:string qty:integer
I have model in a view like this @model List<Products> I can itereate over
I have two model Product and Category, they have has_many, and belongs_to association respectively.
I have a model named product. What i wanted to be able to do

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.