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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:01:55+00:00 2026-05-14T22:01:55+00:00

I have Groups that has_many projects. I also created an order view that is

  • 0

I have Groups that has_many projects. I also created an order view that is similar to my Show view. The reason for creating an additional view is that I am using the Group#show view for a primary display in my site.

So I have the following in my Groups_Controller

 def order
  @group = Group.find(params[:id])
 end

 def sort 
  @group = Group.find(params[:id]) 
  @group.projects.each do |p|
  p.position = params['group_projects'].index(p.id.to_s) + 1
  p.save
 end
render :nothing => true 
end

Then in my view

<ul id="group_projects">
  <% @group.projects.each do |p|%>  
<li class="project_<%= p.id %>"><%= p.title %> - <%= p.position %></li>
  <% end -%>

 <%= sortable_element 'group_projects', :url => { :action => "sort", :id => @group }, :complete  => visual_effect(:highlight, 'group_projects')%>

I have not messed with my routes, but I wonder if thats part of the problem.

So the sorting works but its not saving the position. The error I am getting is the following:

Processing GroupsController#sort (for 127.0.0.1 at 2010-05-03 11:14:19) [POST]
Parameters: {"authenticity_token"=>"vODeoGHH4osrDeBY+fBI/x+YgEs6SJBO15cF/qLqW5o=", "id"=>"1"}
User Load (47.6ms)   SELECT * FROM "users" WHERE ("users"."id" = 1) LIMIT 1
Group Load (0.5ms)   SELECT * FROM "groups" 
Group Load (0.2ms)   SELECT * FROM "groups" WHERE ("groups"."id" = 1) 
Project Load (1.7ms)   SELECT * FROM "projects" WHERE ("projects".group_id = 1) ORDER BY position

NoMethodError (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.index):
app/controllers/groups_controller.rb:136:in `sort'
app/controllers/groups_controller.rb:135:in `sort'

Rendered rescues/_trace (106.7ms)
Rendered rescues/_request_and_response (1.2ms)
Rendering rescues/layout (internal_server_error)

Any ideas on how I can solve this problem. I know there’s a nil.Object, I just don’t see how.

  • 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-14T22:01:56+00:00Added an answer on May 14, 2026 at 10:01 pm

    Without having the line numbers to match with the error, it looks like the line

    p.position = params['group_projects'].index(p.id.to_s) + 1
    

    is where the problem lies. params['group_projects'] is coming back nil for some reason.

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

Sidebar

Related Questions

No related questions found

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.