2
我得到一個關聯錯誤(使用簡單形式),但我相信我的模型被設置得當..看到下面..謝謝!Rails協會錯誤
ArgumentError in User_steps#show
Showing /Users/nelsonkeating/Desktop/ReminDeal/app/views/user_steps/occasions.html.erb where line #17 raised:
Association cannot be used in forms not associated with an object
Extracted source (around line #17):
14:
15: <h3>Related Interest</h3>
16:
17: <li><%= occasion_o.association :interests, :label => false, :as => :check_boxes %></li>
18:
19:
20:
Rails.root: /Users/nelsonkeating/Desktop/ReminDeal
Application Trace | Framework Trace | Full Trace
simple_form (2.0.2) lib/simple_form/form_builder.rb:171:in `association'
app/views/user_steps/occasions.html.erb:17:in `block (2 levels) in _app_views_user_steps_occasions_html_erb___2581036131298452069_70258891699320'
actionpack (3.2.3) lib/action_view/helpers/capture_helper.rb:40:in `block in capture'
actionpack (3.2.3) lib/action_view/helpers/capture_helper.rb:187:in `with_output_buffer'
haml (3.1.6) lib/haml/helpers/xss_mods.rb:109:in `with_output_buffer_with_haml_xss'
actionpack (3.2.3) lib/action_view/helpers/capture_helper.rb:40:in `capture'
haml (3.1.6) lib/haml/helpers/action_view_mods.rb:105:in `capture_with_haml'
actionpack (3.2.3) lib/action_view/helpers/form_helper.rb:606:in `fields_for'
client_side_validations (3.1.4) lib/client_side_validations/action_view/form_helper.rb:45:in `fields_for'
actionpack (3.2.3) lib/action_view/helpers/form_helper.rb:1310:in `fields_for'
client_side_validations (3.1.4) lib/client_side_validations/action_view/form_builder.rb:45:in `fields_for_with_client_side_validations'
simple_form (2.0.2) lib/simple_form/action_view_extensions/builder.rb:204:in `simple_fields_for'
app/views/user_steps/occasions.html.erb:9:in `block in _app_views_user_steps_occasions_html_erb___2581036131298452069_70258891699320'
actionpack (3.2.3) lib/action_view/helpers/capture_helper.rb:40:in `block in capture'
actionpack (3.2.3) lib/action_view/helpers/capture_helper.rb:187:in `with_output_buffer'
haml (3.1.6) lib/haml/helpers/xss_mods.rb:109:in `with_output_buffer_with_haml_xss'
actionpack (3.2.3) lib/action_view/helpers/capture_helper.rb:40:in `capture'
haml (3.1.6) lib/haml/helpers/action_view_mods.rb:105:in `capture_with_haml'
actionpack (3.2.3) lib/action_view/helpers/form_helper.rb:606:in `fields_for'
client_side_validations (3.1.4) lib/client_side_validations/action_view/form_helper.rb:45:in `fields_for'
actionpack (3.2.3) lib/action_view/helpers/form_helper.rb:377:in `form_for'
haml (3.1.6) lib/haml/helpers/action_view_mods.rb:183:in `form_for_with_haml'
haml (3.1.6) lib/haml/helpers/xss_mods.rb:132:in `form_for_with_haml_xss'
client_side_validations (3.1.4) lib/client_side_validations/action_view/form_helper.rb:28:in `form_for'
simple_form (2.0.2) lib/simple_form/action_view_extensions/form_helper.rb:33:in `block in simple_form_for'
simple_form (2.0.2) lib/simple_form/action_view_extensions/form_helper.rb:51:in `with_simple_form_field_error_proc'
simple_form (2.0.2) lib/simple_form/action_view_extensions/form_helper.rb:32:in `simple_form_for'
app/views/user_steps/occasions.html.erb:1:in `_app_views_user_steps_occasions_html_erb___2581036131298452069_70258891699320'
actionpack (3.2.3) lib/action_view/template.rb:143:in `block in render'
activesupport (3.2.3) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.3) lib/action_view/template.rb:141:in `render'
actionpack (3.2.3) lib/action_view/renderer/template_renderer.rb:47:in `block (2 levels) in render_template'
actionpack (3.2.3) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (3.2.3) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.3) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.3) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.3) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (3.2.3) lib/action_view/renderer/template_renderer.rb:46:in `block in render_template'
actionpack (3.2.3) lib/action_view/renderer/template_renderer.rb:54:in `render_with_layout'
actionpack (3.2.3) lib/action_view/renderer/template_renderer.rb:45:in `render_template'
actionpack (3.2.3) lib/action_view/renderer/template_renderer.rb:18:in `render'
actionpack (3.2.3) lib/action_view/renderer/renderer.rb:36:in `render_template'
actionpack (3.2.3) lib/action_view/renderer/renderer.rb:17:in `render'
actionpack (3.2.3) lib/abstract_controller/rendering.rb:110:in `_render_template'
actionpack (3.2.3) lib/action_controller/metal/streaming.rb:225:in `_render_template'
actionpack (3.2.3) lib/abstract_controller/rendering.rb:103:in `render_to_body'
actionpack (3.2.3) lib/action_controller/metal/renderers.rb:28:in `render_to_body'
actionpack (3.2.3) lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
actionpack (3.2.3) lib/abstract_controller/rendering.rb:88:in `render'
actionpack (3.2.3) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.2.3) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/benchmark.rb:310:in `realtime'
activesupport (3.2.3) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
activerecord (3.2.3) lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:39:in `render'
remotipart (1.0.2) lib/remotipart/render_overrides.rb:8:in `render'
wicked (0.1.5) lib/wicked/controller/concerns/render_redirect.rb:26:in `render_step'
wicked (0.1.5) lib/wicked/controller/concerns/render_redirect.rb:18:in `render_wizard'
app/controllers/user_steps_controller.rb:11:in `show'
actionpack (3.2.3) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.3) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.3) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.3) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.3) lib/active_support/callbacks.rb:425:in `_run__2706915168785360702__process_action__2447852392914763718__callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.3) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.3) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.3) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.3) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.3) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.3) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.3) lib/action_controller/metal/params_wrapper.rb:205:in `process_action'
activerecord (3.2.3) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.3) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.3) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.3) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.3) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.3) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:36:in `call'
journey (1.0.3) lib/journey/router.rb:68:in `block in call'
journey (1.0.3) lib/journey/router.rb:56:in `each'
journey (1.0.3) lib/journey/router.rb:56:in `call'
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:600:in `call'
rack-pjax (0.5.9) lib/rack/pjax.rb:12:in `call'
client_side_validations (3.1.4) lib/client_side_validations/middleware.rb:18:in `call'
warden (1.1.1) lib/warden/manager.rb:35:in `block in call'
warden (1.1.1) lib/warden/manager.rb:34:in `catch'
warden (1.1.1) lib/warden/manager.rb:34:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/head.rb:14:in `call'
remotipart (1.0.2) lib/remotipart/middleware.rb:30:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/cookies.rb:338:in `call'
activerecord (3.2.3) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:467:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `_run__2512277106516780401__call__4355055174989828965__callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.3) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.3) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.3) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.3) lib/rails/engine.rb:479:in `call'
railties (3.2.3) lib/rails/application.rb:220:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.3) lib/rails/rack/log_tailer.rb:14:in `call'
thin (1.3.1) lib/thin/connection.rb:80:in `block in pre_process'
thin (1.3.1) lib/thin/connection.rb:78:in `catch'
thin (1.3.1) lib/thin/connection.rb:78:in `pre_process'
thin (1.3.1) lib/thin/connection.rb:53:in `process'
thin (1.3.1) lib/thin/connection.rb:38:in `receive_data'
eventmachine (0.12.10) lib/eventmachine.rb:256:in `run_machine'
eventmachine (0.12.10) lib/eventmachine.rb:256:in `run'
thin (1.3.1) lib/thin/backends/base.rb:61:in `start'
thin (1.3.1) lib/thin/server.rb:159:in `start'
rack (1.4.1) lib/rack/handler/thin.rb:13:in `run'
rack (1.4.1) lib/rack/server.rb:265:in `start'
railties (3.2.3) lib/rails/commands/server.rb:70:in `start'
railties (3.2.3) lib/rails/commands.rb:55:in `block in <top (required)>'
railties (3.2.3) lib/rails/commands.rb:50:in `tap'
railties (3.2.3) lib/rails/commands.rb:50:in `<top (required)>'
script/rails:6:in `require'
script/rails:6:in `<main>'
模型
class User ActiveRecord::Base
has_many :occasions
end
class Occasion < ActiveRecord::Base
belongs_to :user
attr_accessible :date, :name, :pname, :user_id, :interest_ids
has_many :person_interests, :as => :person
has_many :interests, :through => :person_interests
end
class PersonInterest < ActiveRecord::Base
attr_accessible :person_id, :person_type, :interest_ids
belongs_to :interest
belongs_to :person, :polymorphic => true
end
class Interest < ActiveRecord::Base
attr_accessible :name
has_many :person_interests
def people
person_interests.includes(:person).map(&:people).flatten.uniq
end
end
user_steps_controller.rb
def show
@user = current_user
@user.friends.build
@user.anniversaries.build
@user.occasions.build
render_wizard
end
查看
<%= simple_form_for @user, url: wizard_path do |f| %>
<div id="single_module">
<div class="pitch">
<h2 class="signup">Step 5: Custom Occasions</h2>
</div>
<div id="input1" style="margin-bottom:4px;" class="clonedInput">
<ul class="testss1">
<%= f.simple_fields_for :occasions do |occasion_o| %>
<li><%= occasion_o.input :name, :placeholder => 'Enter occasion Name' %></li>
<li><%= occasion_o.input :pname, :placeholder => 'Enter persons Name (if necessary)' %></li>
<li><%= occasion_o.input :date, :as => :date_picker, :input_html => { :class => 'special' } %></li>
</ul>
<h3>Related Interest</h3>
<li><%= occasion_o.association :interests, :label => false, :as => :check_boxes %></li>
<%end%>
</br>
</div>
<%= link_to "skip this step", next_wizard_path %>
<%= f.button :submit, 'Submit' %>
<%end%>
該錯誤明確引用了表單,而您沒有發佈它? – sevenseacat
@卡羅爾哎喲對不起,它是.. – js111