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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:16:27+00:00 2026-05-19T04:16:27+00:00

I currently have a Rails Apps that lets users drag and drop certain elements

  • 0

I currently have a Rails Apps that lets users drag and drop certain elements of the webpage and updates the application based on the users choice. This is done with the help of the Rails helpers and AJAX. However I keep running into a “NoMethodError” in Ruby.

NoMethodError in ProjectsController#member_change

undefined method `symbolize_keys' for nil:NilClass

Here is the method that is being called. My trace says that error is occurring in this line:

before  = u.functions_for(r.authorizable_id)
              u.roles << r unless u.roles.include? r
              u.save
              flag_changed = true
              after = u.functions_for(r.authorizable_id)

And here is the function being called

 def member_change
    flag_changed = false
    params['u'] =~ /role_(\d+)_user_(\d+)/
    drag_role_id = $1
    user_id = $2
    params['r'] =~ /role_(\d+)/
    drop_role_id = $1
    if u=User.find(user_id)
      if r=Role.find(drop_role_id)
        if drag_role_id.to_i !=0 and old_r=Role.find(drag_role_id)
          if drag_role_id == drop_role_id #fom A to A => nothing happen
            flash.now[:warning] = _('No Operation...')
          elsif r.authorizable_id == old_r.authorizable_id #the same project?
            old_r.users.delete(u)
            unless old_r.valid?
              flash.now[:warning] = _('Group "Admin" CAN NOT be EMPTY.') 
              old_r.users << u #TODO: better recovery
              member_edit #if flag_changed
              render :action => :member_edit, :layout => 'module_with_flash'
              return
            end
            old_r.save
            r.users << u unless r.users.include? u
            r.save
            flag_changed = true
            before = u.functions_for(r.authorizable_id)
            after = u.functions_for(r.authorizable_id)
            added = after - before
            removed = before - after
            added.each do |f|
              ApplicationController::send_msg(:function,:create,
                                              {:function_name => f.name, 
                                                :user_id => u.id,
                                                :project_id => r.authorizable_id
                                              })
            end
            removed.each do |f|
              ApplicationController::send_msg(:function,:delete,
                                              {:function_name => f.name, 
                                                :user_id => u.id,
                                                :project_id => r.authorizable_id
                                              })
            end
            flash.now[:notice] = _( 'Move User to Group' ) + " #{ r.name }" 
          else
            flash.now[:warning] = 
              _('You can\'t move User between Groups that belong to different Projects.')
          end
        else
          before  = u.functions_for(r.authorizable_id)
          u.roles << r unless u.roles.include? r
          u.save
          flag_changed = true
          after = u.functions_for(r.authorizable_id)
          added = after - before
          added.each do |f|
            ApplicationController::send_msg(:function,:create,
                                            {:function_name => f.name, 
                                              :user_id => u.id,
                                              :project_id => r.authorizable_id
                                            })
          end
          flash.now[:notice] = _( 'Add User into Group' ) + " #{ r.name }"
        end
      else
        flash.now[:warn] = _( 'Group doesn\'t exist!' ) + ": #{ r.name }"
      end 
    else
      flash.now[:warning] = _( 'User doesn\'t exist!' ) + ": #{ u.login }"
    end
    member_edit #if flag_changed
    render :action => :member_edit, :layout => 'module_with_flash'
  end

and the JavaScript used to call the function

jQuery('#RemoveThisMember').droppable({accept:'.RolesUsersSelection', drop:function(ev,ui){
    if (confirm("This will remove User from this Group, are you sure?"))
    {jQuery.ajax({data:'u=' + encodeURIComponent(jQuery(ui.draggable).attr('id')), success:function(request){jQuery('#module_content').html(request);}, type:'post', url:'/of/projects/11/member_delete'});}
    }, hoverClass:'ProjectRoleDropDelete_active'})

Any ideas?

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-19T04:16:27+00:00Added an answer on May 19, 2026 at 4:16 am

    Time to refactor! Probably into methods about a fifth of that size.

    I suspect that the functions_for method is the cause, could you paste its definition?

    In the mean time, some general suggestions:

    • give your variables full names – user instead of u.
    • you don’t need keep a flag_changed var, check user.changed? (also user._new_record?).
    • you should have your routing set up such that you don’t need to regex the params object.
    • you should almost never have more than a couple of levels of conditionals – refactor into external methods.
    • The is almost certainly a better way to be doing whatever you are with the ApplicationController::send_msg method (logging?). If you can’t use an existing project, make it a helper method in ApplicationController.

    I suspect you’ve switched recently from a much lower level language? You’ll find embracing ruby conventions will save you a lot of time and code.

    Just curious, what does the _ method do?

    Hope this is helpful.

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

Sidebar

Related Questions

I want to have generalised email templates. Currently I have multiple email templates with
We manage a site for a medical charity. They have a number of links
I am using a 3rd-party rotator object, which is providing a smooth, random rotation
IE is giving me an undefined NAN when i try to view the calender...

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.