On 8 April 2016 at 12:51, Naveed Alam <li...@ruby-forum.com> wrote: >> >> Colin > > I get the following error when I goto the privilege page. > > NoMethodError in Employee#edit_privilege > > Showing app/views/employee/edit_privilege.html.erb where line #82 > raised: > > You have a nil object when you didn't expect it! > You might have expected an instance of ActiveRecord::Base. > The error occurred while evaluating nil.[] > Extracted source (around line #82): > > 79: <table width="100%" align="center" cellspacing="1" > cellpadding="1" class="table_design"> > 80: <tr> > 81: <% @privilege_tags.each_with_index do > |privilege_tag,ind| %> > 82: <% all_privileges = > privilege_tag.privileges.all(:conditions=>"name<>'FinanceControl'",:order=>"priority > ASC").select{|p| p.applicable?} %>
You can get a better handle on this by splitting the above lines into multiple lines, so something like <% all_privileges =privilege_tag.privileges.all(:conditions=>"name<>'FinanceControl'",:order=>"priority ASC") %> <% all_privileges = all_privileges.select{|p| p.applicable?} %> Then you can find which bit is causing the error. What is p.applicable? Colin > 83: <% if all_privileges.count > 0 %> > 84: <% if ind==0 or ind==1 or ind==4 %> > 85: <td> > > > > The development log is below: > > Processing EmployeeController#edit_privilege (for 127.0.0.1 at > 2016-03-26 13:49:00) [GET] > Parameters: {"action"=>"edit_privilege", "controller"=>"employee", > "id"=>"emp-0002"} > [4;35;1mUser Load (1.0ms)[0m [0mSELECT * FROM `users` WHERE > (`users`.`id` = 1) AND (`users`.`is_deleted` = 0) [0m > [4;36;1mConfiguration Load (1.0ms)[0m [0;1mSELECT * FROM > `configurations` WHERE (`configurations`.`config_key` = 'Locale') LIMIT > 1[0m > > > > > edit_privilge method in controller is below > > def edit_privilege > @user = User.active.first(:conditions => ["username LIKE > BINARY(?)",params[:id]]) > @employee = @user.employee_record > @privilege_tags=PrivilegeTag.find(:all,:order=>"priority ASC") > @user_privileges=@user.privileges > if request.post? > new_privileges = params[:user][:privilege_ids] if params[:user] > new_privileges ||= [] > @user.privileges = Privilege.find_all_by_id(new_privileges) > redirect_to :action => 'admission4',:id => @employee.id > end > end > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscr...@googlegroups.com. > To post to this group, send email to rubyonrails-talk@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/rubyonrails-talk/926003e903b01ebb2f201a77d2ac328d%40ruby-forum.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLvh4zSrkrGf%3DONUhhjbcT_vkDZvtC43e3wACLe5anog7g%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.