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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:00:15+00:00 2026-05-17T17:00:15+00:00

I’m working on a moderating feature for my application, which is based on a

  • 0

I’m working on a moderating feature for my application, which is based on a basic scaffold structure. What I need, is to edit several records with the boolean parameter publised on false. In moderate.html I’m getting the list of all unpublished entries with the ability to change their parameters which, what and published. The error appears, when I’m trying to save the changes through the complete action.

ArgumentError in NamesController#complete

Unknown key(s): 7, 1, 4

The “7, 1, 4” are id of my unpublished records.

Here are the parts of my code:

#names_controller.rb

    def moderate
     @names = Name.find(:all, params[:name_ids], :conditions => {:published => false})
      respond_to do |format|
        format.html { render :action => "moderate" }
         format.xml 
       end
     end

def complete
     @names = Name.find(params[:name_ids])
     @names.each do |name|
       name.update_attributes!(params[:name].reject { |k,v| v.blank? })
     end
     flash[:notice] = "Updated records!"
     redirect_to names_path
   end


#moderate.html.erb
<% form_tag complete_names_path do %>  
  <% @names.each do |name| %>
    <fieldset>
    <% fields_for "name_ids[#{name.id}]", name do |name_fields| %>
    <%= name_fields.text_field :which %>
    <%= name_fields.text_field :what %>
    <%= name_fields.check_box :published %> 
    <% end %>
    </fieldset>   
  <% end %>  
<%= submit_tag "Ok" %>
<% end %>/


#routes.rb
ActionController::Routing::Routes.draw do |map| 
  map.connect 'moderate', :controller => 'names', :action => 'moderate'
  map.resources :names, :collection => { :complete => :put}
  map.root :names
  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'

I understand, that there’s something wrong with the name_ids, but don’nt understand, what should I do.
Thank you in advance.

ruby 1.8.7 (2009-06-12 patchlevel 174)

[universal-darwin10.0] Rails 2.3.5

Rails log for moderate and complete actions:

Processing NamesController#moderate (for 127.0.0.1 at 2010-10-16 21:36:42)
[GET] [4;35;1mName Load (0.6ms)[0m
[0mSELECT * FROM “names” WHERE
(“names”.”published” = ‘f’) [0m
Rendering template within
layouts/names Rendering names/moderate
Completed in 12ms (View: 7, DB: 1) |
200 OK [http://localhost/moderate]

Processing NamesController#complete
(for 127.0.0.1 at 2010-10-16 21:36:49)
[POST] Parameters: {“commit”=>”Ok”,
“authenticity_token”=>”CtmsjIavksOMSIArrdovkkzuZzHVjkenFFMO5bHIvgg=”,
“name_ids”=>{“7″=>{“published”=>”0”,
“what”=>”Партия”, “which”=>”Крутая”},
“1”=>{“published”=>”1”,
“what”=>”Россия”, “which”=>”Единая”},
“4”=>{“published”=>”0”,
“what”=>”Организация”,
“which”=>”Молдавская”}}}
[4;36;1mName Load (0.4ms)[0m
[0;1mSELECT * FROM “names” WHERE
(“names”.”id” IN (7,1,4)) [0m

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.reject):
app/controllers/names_controller.rb:47:in
complete'
app/controllers/names_controller.rb:46:in
each’
app/controllers/names_controller.rb:46:in
`complete’

Rendered rescues/_trace (110.3ms)
Rendered rescues/_request_and_response
(0.5ms) Rendering rescues/layout
(internal_server_error)

  • 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-17T17:00:15+00:00Added an answer on May 17, 2026 at 5:00 pm

    Likely you need to get just the keys from the name_ids hash. Try:

    @names = Name.find(params[:name_ids].keys)
    

    A separate problem is your reference to params[:name], which is nil. Did you mean (EDIT: use to_s to match the params key, lol):

    @names.each do |name|
      name.update_attributes!(params[:name_ids][name.id.to_s].reject { |k,v| v.blank? })
    end
    

    EDIT (brief-ish explanation):

    What was happening was that you had a nested hash in the params, params[:name_ids]. It looked like:

    "name_ids"=>{"7"=>{"published"=>"0", "what"=>"Партия", "which"=>"Крутая"}, "1"=>{"published"=>"1", "what"=>"Россия", "which"=>"Единая"}, "4"=>{"published"=>"0", "what"=>"Организация", "which"=>"Молдавская"}}
    

    An ActiveRecord ‘find’ method can take an array of ids, but not a hash of values. What you were originally submitting to ‘find’ in this line:

    @names = Name.find(params[:name_ids])
    

    …was the value for params[:name_ids]:

    {"7"=>{"published"=>"0", "what"=>"Партия", "which"=>"Крутая"}, "1"=>{"published"=>"1", 
    "what"=>"Россия", "which"=>"Единая"}, "4"=>{"published"=>"0", "what"=>"Организация", 
    "which"=>"Молдавская"}
    

    When what you wanted was:

    @names = Name.find(['7','1','4'])
    

    which is what calling params[:name_ids].keys gives you.

    The second problem was this line:

    name.update_attributes!(params[:name].reject { |k,v| v.blank? })
    

    There was no value ‘:name’ in params, so calling ‘reject’ on it cause the ‘no method’ error — there is no ‘reject’ method on the nil object. What you wanted was to update the attributes for the ‘name’ that corresponded to the particular name in the loop. This meant you wanted to get the values out of params[:name_ids][:id] where :id was the id of ‘name’.

    It all goes back to the way fields_for created the params to begin with. This line:

    <% fields_for "name_ids[#{name.id}]", name do |name_fields| %>
    

    meant that params would contain a hash called ‘name_ids’, with keys corresponding to name.id, that themselves would contain hashes of attributes that ActiveRecord could use in the update_attributes method.

    There’s a good bit of the famous Rails magic to keep track of in there — does that help?

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.