0

当我尝试创建新的 GroupLink 时出现此错误

控制器代码:

def new
  @group_links=GroupLink.new
  respond_to do |format|
  format.html { render(:template=> 'group_links/new_link_details', :layout =>      
  '/layouts/sponsored_group_manage_sub_menu') }
  end
end

 def create
   @group_link=GroupLink.new(params[:group_link])
   @group_link.group_id=params[:group_id]
    if @group_link.save
    flash[:notice] = "A new booth link was created!"
     else
    flash[:errors] = @group_link.errors
   end
   redirect_to group_group_links_path(@group)
  end

模型关系是一对多的关联:

 class GroupLink < ActiveRecord::Base
    belongs_to :group
    validates_presence_of :url
    validates_presence_of :text

 def link
   self.url
 end

 def text
  self.text
 end
end

 class Group < ActiveRecord::Base
    has_many :group_links, :dependent => :destroy
 end

路由文件有以下内容:

resources :groups do
 member do
  get :get_group_links
 end

 resources :group_links
 ...
end

视图文件如下:

  <% content_for(:page_title, "Create a New Booth Link") -%>
  <% form_for(:group_link,:url => group_group_links_path, :html => {:id => 
    "new_group_link", :method => :post}) do |f| %>
  <fieldset>
 <h6>New Booth Link</h6>
  <label for="group_link_url">URL</label><br />
  <%= f.text_field :url, :size => 32, :placeholder => "URL for the booth link" %><br    
      /><br />
  <label for="group_link_text">Text</label><br />
  <%= f.text_field :text, :size => 32, :placeholder => "The text for this booth 
     link" %><br/><br />
     <div class="buttons">
 <%= f.submit "Create Booth Link", :class => "button large" %>
    </div>
    </fieldset>
 <% end %>

当我错误地将模型创建为 group_links 而不是 group_link 时,问题就开始了。所以我回滚了迁移并销毁了模型并使用正确的名称重新创建了它。在我进行此更改后,它开始抛出此错误(它正在使用 group_links 模型正确创建新的组链接,但正如预期的那样,路由 wnet haywire 所以我决定更改它)

请帮忙,我只是无法弄清楚问题是什么......

以下是完整的堆栈跟踪:

app/models/group_link.rb:12:in `text'
app/models/group_link.rb:12:in `text' activemodel (3.0.20) lib/active_model/errors.rb:224:in `read_attribute_for_validation'

activemodel (3.0.20) lib/active_model/errors.rb:224:in send' activemodel (3.0.20) lib/active_model/errors.rb:224:inadd_on_blank' activemodel (3.0.20) lib/active_model/errors.rb:223:in each' activemodel (3.0.20) lib/active_model/errors.rb:223:inadd_on_blank' activemodel (3.0.20) lib/active_model/validations/ Presence.rb:9:in validate' activesupport (3.0.20) lib/active_support/callbacks.rb:315:insend' activesupport (3.0.20) lib/active_support/callbacks.rb:315:in _callback_before_7973' activesupport (3.0.20) lib/active_support/callbacks.rb:420:in _run_validate_callbacks' activemodel (3.0.20) lib/active_model/validations.rb:212:in run_validations!' activemodel (3.0.20) lib/active_model/validations/callbacks.rb:67:in run_validations!' activesupport (3.0.20) lib/active_support/callbacks.rb:419:in _run_validation_callbacks' activemodel (3.0.20) lib/active_model/validations/callbacks.rb:67:in run_validations!' activemodel (3.0.20) lib/active_model/validations.rb:179:valid?' activerecord (3.0.20) lib/active_record/validations.rb:55:in有效吗?activerecord (3.0.20) lib/active_record/validations.rb:75:in perform_validations' activerecord (3.0.20) lib/active_record/validations.rb:43:insave' activerecord (3.0.20) lib/active_record/attribute_methods/dirty.rb:21:insave' activerecord (3.0.20) lib/active_record/transactions.rb:240:in保存'activerecord (3.0.20) lib/active_record/transactions.rb:292:in with_transaction_returning_status' activerecord (3.0.20) lib/active_record/connection_adapters/abstract/database_statements.rb:139:in transaction' activerecord (3.0.20) lib/active_record/transactions.rb:207:in transaction_without_trace_ActiveRecord_self_name_transaction' newrelic_rpm (3.3.4.1) lib/new_relic/agent/method_tracer.rb:491:in transaction' newrelic_rpm (3.3.4.1) lib/new_relic/ agent/method_tracer.rb:242:in trace_execution_scoped' newrelic_rpm (3.3.4.1) lib/new_relic/agent/method_tracer.rb:486:in transaction' activerecord (3.0.20) lib/active_record/transactions.rb:290:in with_transaction_returning_status' activerecord (3.0.20) lib/active_record/transactions.rb:240:insave' activerecord (3.0.20) lib/active_record/transactions.rb:251:in rollback_active_record_state!' activerecord (3.0.20) lib/active_record/transactions.rb:239:insave' app /controllers/group_links_controller.rb:23:in create' actionpack (3.0.20) lib/action_controller/metal/implicit_render.rb:4:in send_action' actionpack (3.0.20) lib/action_controller/metal/implicit_render.rb:4:in send_action' actionpack (3.0.20) lib/abstract_controller/base.rb:150:in process_action' actionpack (3.0.20) lib/action_controller/metal/rendering.rb:11 :in process_action' actionpack (3.0.20) lib/abstract_controller/callbacks.rb:18:in process_action' activesupport (3.0.20) lib/active_support/callbacks.rb:511:in _run__584584438__process_action__43712543__callbacks' activesupport (3.0.20) lib/active_support/callbacks.rb:410:in发送'activesupport (3.0.20) lib/active_support/callbacks.rb:410:in _run_process_action_callbacks' activesupport (3.0.20) lib/active_support/callbacks.rb:94:in发送'activesupport (3.0.20) lib/active_support/callbacks.rb:94:in run_callbacks' actionpack (3.0.20) lib/abstract_controller/callbacks.rb:17:inprocess_action' actionpack (3.0.20) lib/action_controller/ metal/rescue.rb:17:in process_action' actionpack (3.0.20) lib/action_controller/metal/instrumentation.rb:30:inprocess_action' activesupport (3.0.20) lib/active_support/notifications.rb:52:in instrument' activesupport (3.0.20) lib/active_support/notifications/instrumenter.rb:21:ininstrument' activesupport (3.0.20) lib/active_support/notifications.rb:52:in instrument' actionpack (3.0.20) lib/action_controller/metal/instrumentation.rb:29:inprocess_action' newrelic_rpm (3.3.4.1) lib/new_relic/agent/instrumentation/rails3/action_controller.rb:34:in process_action' newrelic_rpm (3.3.4.1) lib/new_relic/agent/instrumentation/controller_instrumentation.rb:255:in perform_action_with_newrelic_trace'newrelic_rpm (3.3.4.1) lib/new_relic/agent/method_tracer.rb:242:in trace_execution_scoped' newrelic_rpm (3.3.4.1) lib/new_relic/agent/instrumentation/controller_instrumentation.rb:250:in perform_action_with_newrelic_trace'newrelic_rpm (3.3.4.1 ) lib/new_relic/agent/instrumentation/rails3/action_controller.rb:33: 在process_action' actionpack (3.0.20) lib/abstract_controller/base.rb:119:inprocess' actionpack (3.0.20) lib/abstract_controller/rendering.rb:41:in process' actionpack (3.0.20) lib/action_controller/metal.rb:138:indispatch' actionpack (3.0.20) lib/action_controller/metal/rack_delegation.rb:14:in dispatch' actionpack (3.0.20) lib/action_controller/metal.rb:178:in action' actionpack (3.0.20) lib/ action_dispatch/routing/route_set.rb:68:in call' actionpack (3.0.20) lib/action_dispatch/routing/route_set.rb:68:indispatch' actionpack (3.0.20) lib/action_dispatch/routing/route_set.rb:33:in call' rack-mount (0.6.14) lib/rack/mount/route_set.rb:148:incall' 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:131:inoptimize_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:incall' actionpack (3.0.20) lib/action_dispatch/routing/route_set.rb:499:in call' newrelic_rpm (3.3.4.1) lib/new_relic/rack/browser_monitoring.rb:23:incall 'newrelic_rpm (3.3.4.1) lib/new_relic/rack/developer_mode.rb:24:in call'warden call' sass (3.2.5) lib/sass/./sass/plugin/rack.rb:54:in(1.0.6) lib/warden/manager.rb:35:in call' warden (1.0.6) lib/warden/manager.rb:34:incatch'warden (1.0.6) lib/warden /经理。RB:34:在call' actionpack (3.0.20) lib/action_dispatch/middleware/best_standards_support.rb:17:incall' actionpack (3.0.20) lib/action_dispatch/middleware/head.rb:14:in call' rack (1.2.7) lib/rack/methodoverride.rb:24:incall' actionpack (3.0.20) lib/action_dispatch/middleware/params_parser.rb:21:in call' actionpack (3.0.20) lib/action_dispatch/middleware/flash.rb:182:in call' actionpack (3.0.20) lib/action_dispatch/middleware/session/abstract_store.rb:149:in call' actionpack (3.0.20) lib/action_dispatch/middleware/cookies.rb:302:in call'activerecord (3.0.20) lib/active_record/query_cache.rb:32:in call' activerecord (3.0.20) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in cache' activerecord (3.0.20) lib/active_record/query_cache.rb: 12:in cache' activerecord (3.0.20) lib/active_record/query_cache.rb:31:in call' activerecord (3.0.20) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in call' actionpack (3.0.20) lib/action_dispatch/middleware/callbacks.rb:46:incall' activesupport (3.0.20) lib/active_support/callbacks.rb:416:in _run_call_callbacks' actionpack (3.0.20) lib/action_dispatch/middleware/callbacks.rb:44:in call' rack (1.2 .7) lib/rack/sendfile.rb:106:in call' actionpack (3.0.20) lib/action_dispatch/middleware/remote_ip.rb:48:incall' actionpack (3.0.20) lib/action_dispatch/middleware/show_exceptions.rb:47:incall' railties (3.0.20) lib/rails/rack/logger.rb:13:incall' rack (1.2.7) lib/rack/runtime.rb:17:in call' activesupport (3.0.20) lib/active_support/cache/strategy/local_cache.rb:72:incall' rack (1.2.7) lib/rack/lock.rb:13:in call' rack (1.2.7) lib/rack/lock.rb:13:insynchronize' rack (1.2.7) lib/rack/ lock.rb:13:in call' actionpack (3.0.20) lib/action_dispatch/middleware/static.rb:30:incall' railties (3.0.20) lib/rails/application.rb:168:in call' railties (3.0.20) lib/rails/application.rb:77:insend' railties (3.0.20) lib/rails/application.rb:77:in method_missing' railties (3.0.20) lib/rails/rack/log_tailer.rb:14:incall' rack (1.2 .7) lib/rack/content_length.rb:13:in call' rack (1.2.7) lib/rack/handler/webrick.rb:52:inservice' /home/vasu/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/httpserver.rb:104:in service' /home/vasu/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/httpserver.rb:65:in run '/home/vasu/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:173:in start_thread' /home/vasu/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:162:in start'/home/vasu/.rvm/rubies/ruby-1.8。 7-p371/lib/ruby/1.8/webrick/server.rb:162:in start_thread' /home/vasu/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:95:in start' /home/vasu/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb :92:在 each' /home/vasu/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:92:in 开始'/home/vasu/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:23:in start' /home/vasu/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:82:in start' rack (1.2.7) lib/rack/handler/webrick .rb:13:in run' rack (1.2.7) lib/rack/server.rb:217:instart' railties (3.0.20) lib/rails/commands/server.rb:65:in start' railties (3.0.20) lib/rails/commands.rb:30 railties (3.0.20) lib/rails/commands.rb:27:in tap' railties (3.0.20) lib/rails/commands.rb:27 script/rails:6:在“需要”脚本/rails:6

4

1 回答 1

2

我看到的问题是方法GroupLink

 def text
  self.text
 end

您正在定义text只是调用自身的方法。尝试删除此方法。

于 2013-03-20T14:06:35.633 回答