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

The Archive Base Latest Questions

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

I am trying to create two little buttons with an up and down arrow,

  • 0

I am trying to create two little buttons with an up and down arrow, and sort my Products based on that. I have a model called Product, and am using acts_as_list to keep track of position.

Do I do something like this in my controller to create the routes?

resources :products
post "products/move_up"
post "products/move_down"

and in my products controller

def move_up
  @product.find(params[:id])
  @product.move_higher
end

def move_down
  @product.find(params[:id])
  @product.move_lower
end

and in my view

<%= link_to "UP", products_move_up_path(product) %>
<%= link_to "Down", products_move_down_path(product) %>

But I’m not doing something right. I keep getting the error

Couldn’t find Product with id=move_up

Can anyone help me create this route relationship?

EDIT:
Now I am getting the error

You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.find

Here is some more code

View Code

<ul>
<% item.children.each do |child| %>
<li id='category_<%=child.id %>'>
  <span><%= child.name %></span>

  <% child.products.position.each do |product| %>
    <br /><%= link_to "UP", move_up_product_path(product), method: :put %> | 
    <%= link_to "Down", move_down_product_path(product), method: :put %> ----------<%= product.position %> 
   <%= product.name %>
    <%= link_to 'Edit', edit_product_path(product) %>
    <%= link_to 'Delete', product, :method => :delete, :confirm => "Are you sure you want to delete this product?" %> <br />

    <% end %> 
  <%= render 'shared/children', :item => child unless child.leaf? %>
  </li>
 <% end %> <br />
 </ul>

The code it seems to be hanging up on is here

 def move_up
   #Need to add a before filter to find product so I don't have to keep doing it.
   @product.find(params[:product])
   @product.move_higher
 end

When it executes the find. Thanks!

  • 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:57:59+00:00Added an answer on May 30, 2026 at 11:57 pm

    So ‘Up’ and ‘Down’ are really more of an update, so you’d want to use ‘PUT’, but also, your not defining your routes correctly. Try this:

    resources :products do 
      member do
        put :move_up
        put :move_down
      end
    end
    

    Which should create the routes that you are looking for.

    Also, your links need to perform a :put, instead of a :get which is the default action for a link. Try this:

    <%= link_to "UP", move_up_product_path(product), method: :put %>
    

    That should work for you, to check your routes you can always run rake routes

    Hope this helps, just accept/up vote if it does!

    Joe

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

Sidebar

Related Questions

i'm just trying to create this little simulator. in a gui, i have two
I'm trying to create a two-level horizontal navigation menu (or menubar) that displays the
I am trying to create a rewrite rule that accomplishes two things: Redirect (www.)?domain.com
I'm trying to create a method that will sum two timeO objects and return
I am a little confused by the object model of Python. I have two
I'm trying to create two ASP.NET Membership login pages for an ASP.NET website I'm
I am trying to create two different sets of settings for datepicker( http://keith-wood.name/datepick.html )
I'm trying to create a standard two-column form, where the first column is a
I'm trying to use the DSACryptoServiceProvider class with C# to create two DLLs: one
I'm trying to create a table with two columns comprising the primary key in

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.