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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:44:20+00:00 2026-05-21T15:44:20+00:00

Amateur rails programmer struggling to use the fields_for form builder. My rails application (on

  • 0

Amateur rails programmer struggling to use the fields_for form builder. My rails application (on v=2.3.11) tracks laboratory protocols and the animals used on those protocols (their weights, etc).

My specific problem is that protocols can only have a certain number of animals, but that number allowed is specific to a species.

The nested form behavior should display a listing of all the species of animals and an edit box for the number allowed on the protocol.

Models: Protocol, Allowed_Animal, Species

Species Model

class Species < ActiveRecord::Base
  has_many :animals, :order => "band"
  has_many :allowed_animals
end

Protocol Model

class Protocol < ActiveRecord::Base
  has_and_belongs_to_many :animals, :order => "band"
  has_many :allowed_animals
  accepts_nested_attributes_for :allowed_animals
end

Allowed_Animal Model

class AllowedAnimal < ActiveRecord::Base
  belongs_to :protocol
  has_one :species
end

The table for allowed_animal includes:

id, protocol_id, species_id, number, created_at, updated_at

The nested form works like this:

<% form_for(@protocol) do |f| %>
  <%= f.error_messages %>

  <p>
    <%= f.label :title %><br />
    <%= f.text_field :title %>
  </p>
  <p>
    <%= f.label :number %><br />
    <%= f.text_field :number %>
  </p>

  <p>
    Number of animals allowed on protocol:
  </p>
  <div class="left_indent">
    <table>
      <% f.fields_for :allowed_animals, Species.all do |a| %>
      <tr>
        <td><i><%= a.object[:name] %></i></td>
        <td><%= a.text_field :number, :value => @protocol.allowed_animals(a), :size=>2 %></td>
        <%= a.text_field :species_id, :value => a.object[:id], :hidden => true %>
      </tr>
      <% end %>
    </table>
  </div>

  <p>
    Users on protocol:
  </p>
  <div class="left_indent">
    <%= render :partial => 'protocols/users_on_protocol_form', :locals =>{:protocol => @protocol, :users => User.current} %>
  </div>

  <p>
    <%= f.submit 'Save' %>
  </p>
<% end %>

The form displays how I would like it to, but after submission, I get the error:

wrong number of arguments (0 for 1)

in the controller as it tries to do:

@protocol = Protocol.new(params[:protocol])

I am not sure where to go from here. Do I need to have a build method in my model? Or do I need to do anything special in my controller? Is there something wrong with my form_builder code and how it iterates through the species?

Any ideas?

Application trace:

/var/lib/gems/1.8/gems/activerecord-2.3.11/lib/active_record/nested_attributes.rb:343:in `allowed_animals'
/var/lib/gems/1.8/gems/activerecord-2.3.11/lib/active_record/nested_attributes.rb:343:in `send'
/var/lib/gems/1.8/gems/activerecord-2.3.11/lib/active_record/nested_attributes.rb:343:in `assign_nested_attributes_for_collection_association'
/var/lib/gems/1.8/gems/activerecord-2.3.11/lib/active_record/nested_attributes.rb:244:in `allowed_animals_attributes='
/var/lib/gems/1.8/gems/activerecord-2.3.11/lib/active_record/base.rb:2918:in `send'
/var/lib/gems/1.8/gems/activerecord-2.3.11/lib/active_record/base.rb:2918:in `assign_attributes'
/var/lib/gems/1.8/gems/activerecord-2.3.11/lib/active_record/base.rb:2914:in `each'
/var/lib/gems/1.8/gems/activerecord-2.3.11/lib/active_record/base.rb:2914:in `assign_attributes'
/var/lib/gems/1.8/gems/activerecord-2.3.11/lib/active_record/base.rb:2787:in `attributes='
/var/lib/gems/1.8/gems/activerecord-2.3.11/lib/active_record/base.rb:2477:in `initialize'
/media/Data/Animal-Record-Keeping/app/controllers/protocols_controller.rb:42:in `new'
/media/Data/Animal-Record-Keeping/app/controllers/protocols_controller.rb:42:in `create'
/var/lib/gems/1.8/gems/actionpack-2.3.11/lib/action_controller/base.rb:1333:in `send'
/var/lib/gems/1.8/gems/actionpack-2.3.11/lib/action_controller/base.rb:1333:in `perform_action_without_filters'
/var/lib/gems/1.8/gems/actionpack-2.3.11/lib/action_controller/filters.rb:617:in `call_filters'
/var/lib/gems/1.8/gems/actionpack-2.3.11/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark'
/var/lib/gems/1.8/gems/actionpack-2.3.11/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/var/lib/gems/1.8/gems/activesupport-2.3.11/lib/active_support/core_ext/benchmark.rb:17:in `ms'
/var/lib/gems/1.8/gems/activesupport-2.3.11/lib/active_support/core_ext/benchmark.rb:17:in `ms'
/var/lib/gems/1.8/gems/actionpack-2.3.11/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/var/lib/gems/1.8/gems/actionpack-2.3.11/lib/action_controller/rescue.rb:160:in `perform_action_without_flash'
/var/lib/gems/1.8/gems/actionpack-2.3.11/lib/action_controller/flash.rb:151:in `perform_action'
/var/lib/gems/1.8/gems/actionpack-2.3.11/lib/action_controller/base.rb:532:in `send'
/var/lib/gems/1.8/gems/actionpack-2.3.11/lib/action_controller/base.rb:532:in `process_without_filters'
/var/lib/gems/1.8/gems/actionpack-2.3.11/lib/action_controller/filters.rb:606:in `process'
/var/lib/gems/1.8/gems/actionpack-2.3.11/lib/action_controller/base.rb:391:in `process'
/var/lib/gems/1.8/gems/actionpack-2.3.11/lib/action_controller/base.rb:386:in `call'
/var/lib/gems/1.8/gems/actionpack-2.3.11/lib/action_controller/routing/route_set.rb:438:in `call'

Parameters:

{"commit"=>"Save",
 "protocol"=>{"number"=>"Test number",
 "start_date(1i)"=>"2011",
 "start_date(2i)"=>"4",
 "title"=>"Test title",
 "start_date(3i)"=>"12",
 "flight_exempt"=>"0",
 "allowed_animals_attributes"=>{"0"=>{"number"=>"7",
 "id"=>"2",
 "species_id"=>"2"},
 "1"=>{"number"=>"11",
 "id"=>"3",
 "species_id"=>"3"},
 "2"=>{"number"=>"13",
 "id"=>"4",
 "species_id"=>"4"},
 "3"=>{"number"=>"17",
 "id"=>"5",
 "species_id"=>"5"}},
 "summary"=>"Test summary"},
 "user_id"=>{"33"=>"0",
 "6"=>"0",
 "14"=>"0",
 "9"=>"0",
 "37"=>"0",
 "38"=>"0",
 "1"=>"1",
 "39"=>"0",
 "40"=>"0",
 "18"=>"0",
 "31"=>"0",
 "21"=>"0",
 "32"=>"0",
 "5"=>"0"}}

Development Log

# Logfile created on Tue Apr 12 18:11:11 -0400 2011DEPRECATION WARNING: Giving :session_key to SessionStore is deprecated, please use :key instead. (called from new at /var/lib/gems/1.8/gems/actionpack-2.3.11/lib/action_controller/middleware_stack.rb:72)
  [4;36;1mSQL (0.1ms)[0m   [0;1mSET SQL_AUTO_IS_NULL=0[0m


Processing MainController#index (for 127.0.0.1 at 2011-04-12 18:11:12) [GET]
::: Checking session expiry
::: Session has not expired. Reinitialising.
::: Initializing session expiry. Expires at Tue Apr 12 18:26:12 -0400 2011
  [4;35;1mUser Load (0.1ms)[0m   [0mSELECT * FROM `users` WHERE (end_date is null) ORDER BY name[0m
  [4;36;1mUser Load (0.1ms)[0m   [0;1mSELECT * FROM `users` WHERE (end_date is null and job_type regexp 'Weekend') ORDER BY name[0m
  [4;35;1mUser Load (0.1ms)[0m   [0mSELECT * FROM `users` WHERE (end_date is null and job_type regexp 'Medic') ORDER BY name[0m
  [4;36;1mUser Load (0.2ms)[0m   [0;1mSELECT * FROM `users` WHERE (end_date is null and job_type regexp 'Anim') ORDER BY name[0m
Rendering template within layouts/main
Rendering main/index
Rendered layouts/_standard_head (3.2ms)
  [4;35;1mUser Columns (0.5ms)[0m   [0mSHOW FIELDS FROM `users`[0m
  [4;36;1mUser Load (0.1ms)[0m   [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
  [4;35;1mCACHE (0.0ms)[0m   [0mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
  [4;36;1mCACHE (0.0ms)[0m   [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
  [4;35;1mCACHE (0.0ms)[0m   [0mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
  [4;36;1mCACHE (0.0ms)[0m   [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
  [4;35;1mCACHE (0.0ms)[0m   [0mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
  [4;36;1manimal Load (0.1ms)[0m   [0;1mSELECT `animals`.* FROM `animals` INNER JOIN `cages` ON `animals`.cage_id = `cages`.id WHERE ((`cages`.user_id = 1)) ORDER BY band[0m
  [4;35;1manimal Columns (0.5ms)[0m   [0mSHOW FIELDS FROM `animals`[0m
  [4;36;1mCACHE (0.0ms)[0m   [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
  [4;35;1mCACHE (0.0ms)[0m   [0mSELECT `animals`.* FROM `animals` INNER JOIN `cages` ON `animals`.cage_id = `cages`.id WHERE ((`cages`.user_id = 1)) ORDER BY band[0m
  [4;36;1mCACHE (0.0ms)[0m   [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
  [4;35;1mCage Load (0.1ms)[0m   [0mSELECT * FROM `cages` WHERE (date_destroyed is null) AND (`cages`.user_id = 1) ORDER BY name[0m
  [4;36;1mCage Columns (0.4ms)[0m   [0;1mSHOW FIELDS FROM `cages`[0m
  [4;35;1mCACHE (0.0ms)[0m   [0mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
  [4;36;1mCACHE (0.0ms)[0m   [0;1mSELECT * FROM `cages` WHERE (date_destroyed is null) AND (`cages`.user_id = 1) ORDER BY name[0m
Rendered layouts/_menubar (87.9ms)
Rendered layouts/_menubar_login (103.2ms)
  [4;35;1mCACHE (0.0ms)[0m   [0mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
  [4;36;1mprotocols_users Columns (0.5ms)[0m   [0;1mSHOW FIELDS FROM `protocols_users`[0m
  [4;35;1mProtocol Load (0.1ms)[0m   [0mSELECT * FROM `protocols` INNER JOIN `protocols_users` ON `protocols`.id = `protocols_users`.protocol_id WHERE (`protocols_users`.user_id = 1 ) ORDER BY number[0m
  [4;36;1mProtocol Columns (0.4ms)[0m   [0;1mSHOW FIELDS FROM `protocols`[0m
  [4;35;1mTraining Load (0.1ms)[0m   [0mSELECT * FROM `trainings` WHERE (`trainings`.user_id = 1) [0m
  [4;36;1mCACHE (0.0ms)[0m   [0;1mSELECT * FROM `users` WHERE (end_date is null) ORDER BY name[0m
  [4;35;1mCACHE (0.0ms)[0m   [0mSELECT * FROM `users` WHERE (end_date is null) ORDER BY name[0m
  [4;36;1mCACHE (0.0ms)[0m   [0;1mSELECT * FROM `users` WHERE (end_date is null and job_type regexp 'Anim') ORDER BY name[0m
  [4;35;1mCACHE (0.0ms)[0m   [0mSELECT * FROM `users` WHERE (end_date is null and job_type regexp 'Anim') ORDER BY name[0m
  [4;36;1mCACHE (0.0ms)[0m   [0;1mSELECT * FROM `users` WHERE (end_date is null and job_type regexp 'Medic') ORDER BY name[0m
  [4;35;1mCACHE (0.0ms)[0m   [0mSELECT * FROM `users` WHERE (end_date is null and job_type regexp 'Medic') ORDER BY name[0m
  [4;36;1mCACHE (0.0ms)[0m   [0;1mSELECT * FROM `users` WHERE (end_date is null and job_type regexp 'Weekend') ORDER BY name[0m
  [4;35;1mCACHE (0.0ms)[0m   [0mSELECT * FROM `users` WHERE (end_date is null and job_type regexp 'Weekend') ORDER BY name[0m
  [4;36;1mUser Load (0.1ms)[0m   [0;1mSELECT * FROM `users` WHERE (end_date is null and job_type regexp 'Admin') ORDER BY name[0m
  [4;35;1mCACHE (0.0ms)[0m   [0mSELECT * FROM `users` WHERE (end_date is null and job_type regexp 'Admin') ORDER BY name[0m
Rendered main/_sidebar (31.1ms)
Completed in 240ms (View: 197, DB: 3) | 200 OK [http://localhost/]
DEPRECATION WARNING: Giving :session_key to SessionStore is deprecated, please use :key instead. (called from new at /var/lib/gems/1.8/gems/actionpack-2.3.11/lib/action_controller/middleware_stack.rb:72)
  [4;36;1mSQL (0.2ms)[0m   [0;1mSET SQL_AUTO_IS_NULL=0[0m


Processing ProtocolsController#new (for 127.0.0.1 at 2011-04-12 18:11:14) [GET]
::: Checking session expiry
::: Session has not expired. Reinitialising.
::: Initializing session expiry. Expires at Tue Apr 12 18:26:14 -0400 2011
  [4;35;1mProtocol Columns (0.5ms)[0m   [0mSHOW FIELDS FROM `protocols`[0m
Rendering template within layouts/standard
Rendering protocols/new
  [4;36;1mSpecies Load (0.1ms)[0m   [0;1mSELECT * FROM `species` [0m
  [4;35;1mSpecies Columns (0.4ms)[0m   [0mSHOW FIELDS FROM `species`[0m
  [4;36;1mAllowedanimal Load (0.3ms)[0m   [0;1mSELECT * FROM `allowed_animals` WHERE (protocol_id = NULL and species_id = 70099589946800) LIMIT 1[0m
  [4;35;1mAllowedanimal Load (0.1ms)[0m   [0mSELECT * FROM `allowed_animals` WHERE (protocol_id = NULL and species_id = 70099593009960) LIMIT 1[0m
  [4;36;1mAllowedanimal Load (0.1ms)[0m   [0;1mSELECT * FROM `allowed_animals` WHERE (protocol_id = NULL and species_id = 70099592966760) LIMIT 1[0m
  [4;35;1mAllowedanimal Load (0.1ms)[0m   [0mSELECT * FROM `allowed_animals` WHERE (protocol_id = NULL and species_id = 70099592896700) LIMIT 1[0m
  [4;36;1mUser Load (0.1ms)[0m   [0;1mSELECT * FROM `users` WHERE (end_date is null) ORDER BY name[0m
  [4;35;1mUser Columns (0.5ms)[0m   [0mSHOW FIELDS FROM `users`[0m
  [4;36;1mUser Load (0.1ms)[0m   [0;1mSELECT `users`.id FROM `users` INNER JOIN `protocols_users` ON `users`.id = `protocols_users`.user_id WHERE (`users`.`id` = 33) AND (`protocols_users`.protocol_id = NULL ) ORDER BY name LIMIT 1[0m
  [4;35;1mUser Load (0.1ms)[0m   [0mSELECT `users`.id FROM `users` INNER JOIN `protocols_users` ON `users`.id = `protocols_users`.user_id WHERE (`users`.`id` = 38) AND (`protocols_users`.protocol_id = NULL ) ORDER BY name LIMIT 1[0m
  [4;36;1mUser Load (0.0ms)[0m   [0;1mSELECT `users`.id FROM `users` INNER JOIN `protocols_users` ON `users`.id = `protocols_users`.user_id WHERE (`users`.`id` = 21) AND (`protocols_users`.protocol_id = NULL ) ORDER BY name LIMIT 1[0m
  [4;35;1mUser Load (0.1ms)[0m   [0mSELECT `users`.id FROM `users` INNER JOIN `protocols_users` ON `users`.id = `protocols_users`.user_id WHERE (`users`.`id` = 1) AND (`protocols_users`.protocol_id = NULL ) ORDER BY name LIMIT 1[0m
  [4;36;1mUser Load (0.0ms)[0m   [0;1mSELECT `users`.id FROM `users` INNER JOIN `protocols_users` ON `users`.id = `protocols_users`.user_id WHERE (`users`.`id` = 14) AND (`protocols_users`.protocol_id = NULL ) ORDER BY name LIMIT 1[0m
  [4;35;1mUser Load (0.0ms)[0m   [0mSELECT `users`.id FROM `users` INNER JOIN `protocols_users` ON `users`.id = `protocols_users`.user_id WHERE (`users`.`id` = 37) AND (`protocols_users`.protocol_id = NULL ) ORDER BY name LIMIT 1[0m
  [4;36;1mUser Load (0.0ms)[0m   [0;1mSELECT `users`.id FROM `users` INNER JOIN `protocols_users` ON `users`.id = `protocols_users`.user_id WHERE (`users`.`id` = 31) AND (`protocols_users`.protocol_id = NULL ) ORDER BY name LIMIT 1[0m
  [4;35;1mUser Load (0.0ms)[0m   [0mSELECT `users`.id FROM `users` INNER JOIN `protocols_users` ON `users`.id = `protocols_users`.user_id WHERE (`users`.`id` = 39) AND (`protocols_users`.protocol_id = NULL ) ORDER BY name LIMIT 1[0m
  [4;36;1mUser Load (0.1ms)[0m   [0;1mSELECT `users`.id FROM `users` INNER JOIN `protocols_users` ON `users`.id = `protocols_users`.user_id WHERE (`users`.`id` = 5) AND (`protocols_users`.protocol_id = NULL ) ORDER BY name LIMIT 1[0m
  [4;35;1mUser Load (0.0ms)[0m   [0mSELECT `users`.id FROM `users` INNER JOIN `protocols_users` ON `users`.id = `protocols_users`.user_id WHERE (`users`.`id` = 18) AND (`protocols_users`.protocol_id = NULL ) ORDER BY name LIMIT 1[0m
  [4;36;1mUser Load (0.0ms)[0m   [0;1mSELECT `users`.id FROM `users` INNER JOIN `protocols_users` ON `users`.id = `protocols_users`.user_id WHERE (`users`.`id` = 32) AND (`protocols_users`.protocol_id = NULL ) ORDER BY name LIMIT 1[0m
  [4;35;1mUser Load (0.0ms)[0m   [0mSELECT `users`.id FROM `users` INNER JOIN `protocols_users` ON `users`.id = `protocols_users`.user_id WHERE (`users`.`id` = 9) AND (`protocols_users`.protocol_id = NULL ) ORDER BY name LIMIT 1[0m
  [4;36;1mUser Load (0.0ms)[0m   [0;1mSELECT `users`.id FROM `users` INNER JOIN `protocols_users` ON `users`.id = `protocols_users`.user_id WHERE (`users`.`id` = 40) AND (`protocols_users`.protocol_id = NULL ) ORDER BY name LIMIT 1[0m
  [4;35;1mUser Load (0.0ms)[0m   [0mSELECT `users`.id FROM `users` INNER JOIN `protocols_users` ON `users`.id = `protocols_users`.user_id WHERE (`users`.`id` = 6) AND (`protocols_users`.protocol_id = NULL ) ORDER BY name LIMIT 1[0m
Rendered protocols/_users_on_protocol_form (19.7ms)
Rendered protocols/_form (123.0ms)
Rendered layouts/_standard_head (2.4ms)
  [4;36;1mUser Load (0.1ms)[0m   [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
  [4;35;1mCACHE (0.0ms)[0m   [0mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
  [4;36;1mCACHE (0.0ms)[0m   [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
  [4;35;1mCACHE (0.0ms)[0m   [0mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
  [4;36;1mCACHE (0.0ms)[0m   [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
  [4;35;1mCACHE (0.0ms)[0m   [0mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
  [4;36;1manimal Load (0.1ms)[0m   [0;1mSELECT `animals`.* FROM `animals` INNER JOIN `cages` ON `animals`.cage_id = `cages`.id WHERE ((`cages`.user_id = 1)) ORDER BY band[0m
  [4;35;1manimal Columns (0.6ms)[0m   [0mSHOW FIELDS FROM `animals`[0m
  [4;36;1mCACHE (0.0ms)[0m   [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
  [4;35;1mCACHE (0.0ms)[0m   [0mSELECT `animals`.* FROM `animals` INNER JOIN `cages` ON `animals`.cage_id = `cages`.id WHERE ((`cages`.user_id = 1)) ORDER BY band[0m
  [4;36;1mCACHE (0.0ms)[0m   [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
  [4;35;1mCage Load (0.1ms)[0m   [0mSELECT * FROM `cages` WHERE (date_destroyed is null) AND (`cages`.user_id = 1) ORDER BY name[0m
  [4;36;1mCage Columns (0.4ms)[0m   [0;1mSHOW FIELDS FROM `cages`[0m
  [4;35;1mCACHE (0.0ms)[0m   [0mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
  [4;36;1mCACHE (0.0ms)[0m   [0;1mSELECT * FROM `cages` WHERE (date_destroyed is null) AND (`cages`.user_id = 1) ORDER BY name[0m
Rendered layouts/_menubar (122.0ms)
Rendered layouts/_menubar_login (124.0ms)
Rendered layouts/_standard_layout (127.8ms)
Completed in 280ms (View: 266, DB: 4) | 200 OK [http://localhost/protocols/new]
DEPRECATION WARNING: Giving :session_key to SessionStore is deprecated, please use :key instead. (called from new at /var/lib/gems/1.8/gems/actionpack-2.3.11/lib/action_controller/middleware_stack.rb:72)
  [4;35;1mSQL (0.1ms)[0m   [0mSET SQL_AUTO_IS_NULL=0[0m


Processing ProtocolsController#create (for 127.0.0.1 at 2011-04-12 18:11:43) [POST]
  Parameters: {"commit"=>"Save", "protocol"=>{"start_date(1i)"=>"2011", "number"=>"Test Number", "start_date(2i)"=>"4", "start_date(3i)"=>"12", "title"=>"Test Title", "allowed_animals_attributes"=>{"0"=>{"number"=>"7", "id"=>"2", "species_id"=>"2"}, "1"=>{"number"=>"11", "id"=>"3", "species_id"=>"3"}, "2"=>{"number"=>"13", "id"=>"4", "species_id"=>"4"}, "3"=>{"number"=>"17", "id"=>"5", "species_id"=>"5"}}, "flight_exempt"=>"0", "summary"=>"Test Summary"}, "user_id"=>{"6"=>"0", "33"=>"0", "9"=>"0", "14"=>"0", "37"=>"0", "38"=>"0", "40"=>"0", "39"=>"0", "1"=>"1", "18"=>"0", "31"=>"0", "32"=>"0", "21"=>"0", "5"=>"0"}}
::: Checking session expiry
::: Session has not expired. Reinitialising.
::: Initializing session expiry. Expires at Tue Apr 12 18:26:43 -0400 2011
  [4;36;1mProtocol Columns (0.6ms)[0m   [0;1mSHOW FIELDS FROM `protocols`[0m

ArgumentError (wrong number of arguments (0 for 1)):
  app/controllers/protocols_controller.rb:42:in `new'
  app/controllers/protocols_controller.rb:42:in `create'
  /var/lib/gems/1.8/gems/ruby-debug-ide-0.4.9/lib/ruby-debug-ide.rb:109:in `debug_load'
  /var/lib/gems/1.8/gems/ruby-debug-ide-0.4.9/lib/ruby-debug-ide.rb:109:in `debug_program'
  /var/lib/gems/1.8/gems/ruby-debug-ide-0.4.9/bin/rdebug-ide:87
  /var/lib/gems/1.8/bin/rdebug-ide:19:in `load'
  /var/lib/gems/1.8/bin/rdebug-ide:19

Rendered rescues/_trace (46.0ms)
Rendered rescues/_request_and_response (1.7ms)
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-21T15:44:21+00:00Added an answer on May 21, 2026 at 3:44 pm

    I figured out that the problem was that I had a function in my Protocol model with the same name as the model I was trying to nest (AllowedAnimal). When calling protocol.allowed_animals it was calling the function (with not enough arguments) instead of returning the nested fields_for.

    I also had to change the relationship to belongs_to in my Allowed Animal Model to get my allowed_animal.species to work:

    class AllowedAnimal < ActiveRecord::Base
      belongs_to :protocol
      belongs_to :species
    end
    

    And add a method in my model to build out the allowed_animals for a new protocol:

    def build_allowed_animals
      abs = Array.new
      for sp in Species.all
        ab = AllowedAnimal.new
        ab.species = sp
        ab.number = 0
        abs << ab
      end
      self.allowed_animals = abs
    end
    

    Call the method in my Protocol Controller:

    def new
      @protocol = Protocol.new
      @protocol.build_allowed_bats
      respond_to do |format|
        format.html # new.html.erb
        format.xml  { render :xml => @protocol }
      end
    end
    

    And make a few edits to my form:

    <% form_for(@protocol) do |f| %>
      <%= f.error_messages %>
    
      <p>
        <%= f.label :title %><br />
        <%= f.text_field :title %>
      </p>
      <p>
        <%= f.label :number %><br />
        <%= f.text_field :number %>
      </p>
    
      <p>
        Number of animals allowed on protocol:
      </p>
      <div class="left_indent">
        <table>
          <% f.fields_for :allowed_animals do |a| %>
            <tr>
              <td><i><%= a.object.species.name %></i></td>
              <td><%= a.text_field :number, :value => @protocol.determine_allowed_animals(a.object.species), :size=>2 %></td>
              <%= a.text_field :species_id, :value => a.object.species.id, :hidden => true %>
            </tr>
          <% end %>
        </table>
      </div>
    
      <p>
        Users on protocol:
      </p>
      <div class="left_indent">
        <%= render :partial => 'protocols/users_on_protocol_form', :locals =>{:protocol => @protocol, :users => User.current} %>
      </div>
    
      <p>
        <%= f.submit 'Save' %>
      </p>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a bit of a Ruby on Rails amateur, and I am trying to
I am an amateur programmer. When I publish an app from Visual Studio Express,
I'm an amateur programmer that's experimenting using pthreads, to see to what extent a
I'm an amateur C++ programmer trying to learn about basic shell scripting. I have
I am developing a WPF Application using MVVM Architecture. I am an amateur in
Hey, Sorry if this is a dumb question. I'm an amateur programmer and new
I am a long-time, self-taught, amateur VB programmer who is now trying to teach
I'm a total amateur writing a small App to track to changes in folders.
As an amateur software developer (I'm still in academia) I've written a few schemas
Let me preface this by saying I'm a complete amateur when it comes to

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.