Topic: Problem with Formtastic, uninitialized constant Procedure::Servers

Hello,

I'm trying to write a very simple little program so that I can better understand the Has Many Through database relationship, as well as, figure out how to use multi-select boxes.

I started using formtastic after not finding a very good example of the multi-select box with what I was trying to do.

Anyway, so here is the gist of what I'm trying to do. Two complete Scaffolds, Servers (name, ID) and Procedures (name, body, ID) and a join table model (server_id, procedure_id). The goal is to have a user create any number of server objects, and then when creating new procedure objects be able to associate each individual procedure with any number of already created server objects.

So during the create/edit of a procedure they would see a multiselect with all of the already created servers, and be able to highlight any or none of them.

Then when viewing the servers, I want a series of links displaying each procedure.

I've not gotten past the form creation as of yet, I keep getting error message : uninitialized constant Procedure::Servers when trying to use the form.

Here is my Code:

Models

procedure.rb

class Procedure < ActiveRecord::Base
  attr_accessible :name, :body, :server_ids 
  has_many :servers, :through => :procedure_links
  has_many :procedure_links, :dependent => :destroy
  accepts_nested_attributes_for :procedure_links
end

server.rb

class Server < ActiveRecord::Base
  attr_accessible :name, :procedure_ids 
  has_many :procedures, :through => :procedure_links
  has_many :procedure_links, :dependent => :destroy
end

procedure_link.rb

class ProcedureLink < ActiveRecord::Base
  attr_accessible :server_id, :procedure_id 
  belongs_to :servers
  belongs_to :procedures
end

Procedures Form:

<%= semantic_form_for @procedure do |f| %>
  <% if @procedure.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@procedure.errors.count, "error") %> prohibited this procedure from being saved:</h2>

      <ul>
      <% @procedure.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <% f.inputs do %>
    <%= f.input :name %>  
    <%= f.input :body %>  
    <%= f.input :servers  %>
  <% end %>
  <%= f.buttons %>

<% end %>

Gem File:

gem 'formtastic', '~> 1.2.3'

Full Trace:

uninitialized constant Procedure::Servers

Extracted source (around line #17):

14:   <% f.inputs do %>
15:     <%= f.input :name %>  
16:     <%= f.input :body %>  
17:     <%= f.input :servers  %>
18:   <% end %>
19:   <%= f.buttons %>
20: 

Trace of template inclusion: app/views/procedures/edit.html.erb

Rails.root: C:/Sean/rails/ProcedureIT.3
Application Trace | Framework Trace | Full Trace

activerecord (3.0.7) lib/active_record/base.rb:1200:in `compute_type'
activerecord (3.0.7) lib/active_record/reflection.rb:162:in `send'
activerecord (3.0.7) lib/active_record/reflection.rb:162:in `klass'
activerecord (3.0.7) lib/active_record/associations/association_collection.rb:375:in `proxy_respond_to?'
activerecord (3.0.7) lib/active_record/associations/association_proxy.rb:84:in `respond_to?'
formtastic (1.2.4) lib/formtastic.rb:1472:in `is_file?'
activemodel (3.0.7) lib/active_model/attribute_methods.rb:95:in `any?'
formtastic (1.2.4) lib/formtastic.rb:1472:in `each'
formtastic (1.2.4) lib/formtastic.rb:1472:in `any?'
formtastic (1.2.4) lib/formtastic.rb:1472:in `is_file?'
formtastic (1.2.4) lib/formtastic.rb:504:in `error_keys'
formtastic (1.2.4) lib/formtastic.rb:511:in `has_errors?'
formtastic (1.2.4) lib/formtastic.rb:117:in `input'
app/views/procedures/_form.html.erb:17:in `_app_views_procedures__form_html_erb___154438867_36908760_520054'
actionpack (3.0.7) lib/action_view/helpers/capture_helper.rb:40:in `capture'
actionpack (3.0.7) lib/action_view/helpers/capture_helper.rb:172:in `with_output_buffer'
actionpack (3.0.7) lib/action_view/helpers/capture_helper.rb:40:in `capture'
formtastic (1.2.4) lib/formtastic.rb:1367:in `field_set_and_list_wrapping'
formtastic (1.2.4) lib/formtastic.rb:293:in `inputs'
app/views/procedures/_form.html.erb:14:in `_app_views_procedures__form_html_erb___154438867_36908760_520054'
actionpack (3.0.7) lib/action_view/helpers/capture_helper.rb:40:in `capture'
actionpack (3.0.7) lib/action_view/helpers/capture_helper.rb:172:in `with_output_buffer'
actionpack (3.0.7) lib/action_view/helpers/capture_helper.rb:40:in `capture'
actionpack (3.0.7) lib/action_view/helpers/form_helper.rb:545:in `fields_for'
client_side_validations (3.0.5) lib/client_side_validations/action_view/form_helper.rb:45:in `fields_for'
actionpack (3.0.7) lib/action_view/helpers/form_helper.rb:320:in `form_for'
client_side_validations (3.0.5) lib/client_side_validations/action_view/form_helper.rb:28:in `form_for'
formtastic (1.2.4) lib/formtastic.rb:1943:in `semantic_form_for'
formtastic (1.2.4) lib/formtastic.rb:1908:in `with_custom_field_error_proc'
formtastic (1.2.4) lib/formtastic.rb:1942:in `semantic_form_for'
app/views/procedures/_form.html.erb:1:in `_app_views_procedures__form_html_erb___154438867_36908760_520054'
actionpack (3.0.7) lib/action_view/template.rb:135:in `send'
actionpack (3.0.7) lib/action_view/template.rb:135:in `render'
activesupport (3.0.7) lib/active_support/notifications.rb:54:in `instrument'
actionpack (3.0.7) lib/action_view/template.rb:127:in `render'
actionpack (3.0.7) lib/action_view/render/partials.rb:333:in `render_partial'
actionpack (3.0.7) lib/action_view/render/partials.rb:262:in `render'
activesupport (3.0.7) lib/active_support/notifications.rb:52:in `instrument'
activesupport (3.0.7) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.7) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.7) lib/action_view/render/partials.rb:260:in `render'
actionpack (3.0.7) lib/action_view/render/partials.rb:378:in `_render_partial'
actionpack (3.0.7) lib/action_view/render/rendering.rb:31:in `render'
app/views/procedures/edit.html.erb:3:in `_app_views_procedures_edit_html_erb__651260686_36923196_0'
actionpack (3.0.7) lib/action_view/template.rb:135:in `send'
actionpack (3.0.7) lib/action_view/template.rb:135:in `render'
activesupport (3.0.7) lib/active_support/notifications.rb:54:in `instrument'
actionpack (3.0.7) lib/action_view/template.rb:127:in `render'
actionpack (3.0.7) lib/action_view/render/rendering.rb:59:in `_render_template'
activesupport (3.0.7) lib/active_support/notifications.rb:52:in `instrument'
activesupport (3.0.7) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.7) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.7) lib/action_view/render/rendering.rb:56:in `_render_template'
actionpack (3.0.7) lib/action_view/render/rendering.rb:26:in `render'
actionpack (3.0.7) lib/abstract_controller/rendering.rb:115:in `_render_template'
actionpack (3.0.7) lib/abstract_controller/rendering.rb:109:in `render_to_body'
actionpack (3.0.7) lib/action_controller/metal/renderers.rb:47:in `render_to_body'
actionpack (3.0.7) lib/action_controller/metal/compatibility.rb:55:in `render_to_body'
actionpack (3.0.7) lib/abstract_controller/rendering.rb:102:in `render_to_string'
actionpack (3.0.7) lib/abstract_controller/rendering.rb:93:in `render'
actionpack (3.0.7) lib/action_controller/metal/rendering.rb:17:in `render'
actionpack (3.0.7) lib/action_controller/metal/instrumentation.rb:40:in `render'
activesupport (3.0.7) lib/active_support/core_ext/benchmark.rb:5:in `ms'
C:/Ruby/lib/ruby/1.8/benchmark.rb:308:in `realtime'
activesupport (3.0.7) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.0.7) lib/action_controller/metal/instrumentation.rb:40:in `render'
actionpack (3.0.7) lib/action_controller/metal/instrumentation.rb:78:in `cleanup_view_runtime'
activerecord (3.0.7) lib/active_record/railties/controller_runtime.rb:15:in `cleanup_view_runtime'
actionpack (3.0.7) lib/action_controller/metal/instrumentation.rb:39:in `render'
actionpack (3.0.7) lib/action_controller/metal/implicit_render.rb:14:in `default_render'
actionpack (3.0.7) lib/action_controller/metal/implicit_render.rb:6:in `send_action'
actionpack (3.0.7) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.7) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.7) lib/abstract_controller/callbacks.rb:18:in `process_action'
activesupport (3.0.7) lib/active_support/callbacks.rb:436:in `_run__152332330__process_action__155074602__callbacks'
activesupport (3.0.7) lib/active_support/callbacks.rb:410:in `send'
activesupport (3.0.7) lib/active_support/callbacks.rb:410:in `_run_process_action_callbacks'
activesupport (3.0.7) lib/active_support/callbacks.rb:94:in `send'
activesupport (3.0.7) lib/active_support/callbacks.rb:94:in `run_callbacks'
actionpack (3.0.7) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.7) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
activesupport (3.0.7) lib/active_support/notifications.rb:52:in `instrument'
activesupport (3.0.7) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.7) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.7) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.7) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.7) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.7) lib/abstract_controller/rendering.rb:41:in `process'
actionpack (3.0.7) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.7) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.7) lib/action_controller/metal.rb:178:in `action'
actionpack (3.0.7) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.7) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.7) lib/action_dispatch/routing/route_set.rb:27:in `call'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:148:in `call'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:93:in `recognize'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:82:in `optimized_each'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.7) lib/action_dispatch/routing/route_set.rb:493:in `call'
client_side_validations (3.0.5) lib/client_side_validations/middleware.rb:17:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.3) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/cookies.rb:302:in `call'
activerecord (3.0.7) lib/active_record/query_cache.rb:32:in `call'
activerecord (3.0.7) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.7) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.7) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/callbacks.rb:46:in `call'
activesupport (3.0.7) lib/active_support/callbacks.rb:416:in `_run_call_callbacks'
actionpack (3.0.7) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.3) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.7) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.3) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.7) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.3) lib/rack/lock.rb:11:in `call'
rack (1.2.3) lib/rack/lock.rb:11:in `synchronize'
rack (1.2.3) lib/rack/lock.rb:11:in `call'
actionpack (3.0.7) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.7) lib/rails/application.rb:168:in `call'
railties (3.0.7) lib/rails/application.rb:77:in `send'
railties (3.0.7) lib/rails/application.rb:77:in `method_missing'
railties (3.0.7) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.3) lib/rack/content_length.rb:13:in `call'
rack (1.2.3) lib/rack/handler/webrick.rb:52:in `service'
C:/Ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
C:/Ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
C:/Ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
C:/Ruby/lib/ruby/1.8/webrick/server.rb:162:in `start'
C:/Ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
C:/Ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'
C:/Ruby/lib/ruby/1.8/webrick/server.rb:92:in `each'
C:/Ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'
C:/Ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'
C:/Ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'
rack (1.2.3) lib/rack/handler/webrick.rb:13:in `run'
rack (1.2.3) lib/rack/server.rb:217:in `start'
railties (3.0.7) lib/rails/commands/server.rb:65:in `start'
railties (3.0.7) lib/rails/commands.rb:30
railties (3.0.7) lib/rails/commands.rb:27:in `tap'
railties (3.0.7) lib/rails/commands.rb:27
script/rails:6:in `require'
script/rails:6

Request

Parameters:

{"id"=>"1"}

Thanks for any help with this, or if you guys have a better way to do what I'm trying to do I'm also open to that.

Thanks again,

Sean

Re: Problem with Formtastic, uninitialized constant Procedure::Servers

The error you are getting is saying that it doesn't know what Procedure::Servers is. This is not surprising, since there is no Servers class. There is, however, a Server class.

;-)