删除错误的模型文件后出错

时间:2013-03-20 14:01:43

标签: ruby-on-rails ruby-on-rails-3

当我尝试创建新的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

routes文件包含以下内容:

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:在send' activemodel (3.0.20) lib/active_model/errors.rb:224:in add_on_blank&#39;   activemodel(3.0.20)lib / active_model / errors.rb:223:在each' activemodel (3.0.20) lib/active_model/errors.rb:223:in add_on_blank&#39;   activemodel(3.0.20)lib / active_model / validations / presence.rb:9:in   validate' activesupport (3.0.20) lib/active_support/callbacks.rb:315:in发送&#39; activesupport(3.0.20)   lib / active_support / callbacks.rb:315:在_callback_before_7973' activesupport (3.0.20) lib/active_support/callbacks.rb:420:in _ run_validate_callbacks&#39; activemodel(3.0.20)   lib / active_model / validations.rb:212:run_validations!' activemodel (3.0.20) lib/active_model/validations/callbacks.rb:67:in run_validations!&#39; activesupport(3.0.20)   lib / active_support / callbacks.rb:419:在_run_validation_callbacks' activemodel (3.0.20) lib/active_model/validations/callbacks.rb:67:in run_validations!&#39; activemodel(3.0.20)   lib / active_model / validations.rb:179:valid?' activerecord (3.0.20) lib/active_record/validations.rb:55:in有效吗?&#39; activerecord(3.0.20)   lib / active_record / validations.rb:75:in perform_validations' activerecord (3.0.20) lib/active_record/validations.rb:43:in save&#39;   activerecord(3.0.20)   lib / active_record / attribute_methods / dirty.rb:21:in save' activerecord (3.0.20) lib/active_record/transactions.rb:240:in save&#39; 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 交易&#39; activerecord(3.0.20)   LIB / active_record / transactions.rb:207:在   transaction_without_trace_ActiveRecord_self_name_transaction' newrelic_rpm (3.3.4.1) lib/new_relic/agent/method_tracer.rb:491:in 交易&#39; newrelic_rpm(3.3.4.1)   lib / new_relic / agent / method_tracer.rb:242:在trace_execution_scoped' newrelic_rpm (3.3.4.1) lib/new_relic/agent/method_tracer.rb:486:in 事务中&#39; activerecord(3.0.20)   LIB / active_record / transactions.rb:290:在   with_transaction_returning_status' activerecord (3.0.20) lib/active_record/transactions.rb:240:in保存&#39; activerecord(3.0.20)   LIB / active_record / transactions.rb:251:在   rollback_active_record_state!' activerecord (3.0.20) lib/active_record/transactions.rb:239:in保存&#39;   app / controllers / group_links_controller.rb:23:在create' actionpack (3.0.20) lib/action_controller/metal/implicit_render.rb:4:in send_action&#39; actionpack(3.0.20)   lib / action_controller / metal / implicit_render.rb:4:在send_action' actionpack (3.0.20) lib/abstract_controller/base.rb:150:in process_action&#39; actionpack(3.0.20)   lib / action_controller / metal / rendering.rb:11:在process_action' actionpack (3.0.20) lib/abstract_controller/callbacks.rb:18:in process_action&#39; activesupport(3.0.20)   LIB / active_support / callbacks.rb:511:在   _run__584584438__process_action__43712543__callbacks' activesupport (3.0.20) lib/active_support/callbacks.rb:410:in发送&#39;的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发送&#39; activesupport(3.0.20)   lib / active_support / callbacks.rb:94:在run_callbacks' actionpack (3.0.20) lib/abstract_controller/callbacks.rb:17:in process_action&#39;   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:in process_action&#39;   activesupport(3.0.20)lib / active_support / notifications.rb:52:in   instrument' activesupport (3.0.20) lib/active_support/notifications/instrumenter.rb:21:in仪器&#39;   activesupport(3.0.20)lib / active_support / notifications.rb:52:in   instrument' actionpack (3.0.20) lib/action_controller/metal/instrumentation.rb:29:in process_action&#39;   newrelic_rpm(3.3.4.1)   LIB / new_relic /剂/仪表/ Rails3中/ action_controller.rb:34:在   process_action' newrelic_rpm (3.3.4.1) lib/new_relic/agent/instrumentation/controller_instrumentation.rb:255:in perform_action_with_newrelic_trace&#39; newrelic_rpm(3.3.4.1)   lib / new_relic / agent / method_tracer.rb:242:在trace_execution_scoped' newrelic_rpm (3.3.4.1) lib/new_relic/agent/instrumentation/controller_instrumentation.rb:250:in perform_action_with_newrelic_trace&#39; newrelic_rpm(3.3.4.1)   LIB / new_relic /剂/仪表/ Rails3中/ action_controller.rb:33:在   process_action' actionpack (3.0.20) lib/abstract_controller/base.rb:119:in过程&#39; actionpack(3.0.20)   lib / abstract_controller / rendering.rb:41:在process' actionpack (3.0.20) lib/action_controller/metal.rb:138:in发送&#39; 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 动作&#39; actionpack(3.0.20)   lib / action_dispatch / routing / route_set.rb:68:在call' actionpack (3.0.20) lib/action_dispatch/routing/route_set.rb:68:in发送&#39;   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:in呼叫&#39;   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:in optimized_each&#39;机架式   (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&#39;   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:in呼叫&#39; newrelic_rpm   (3.3.4.1)lib / new_relic / rack / developer_mode.rb:24:in call' sass (3.2.5) lib/sass/./sass/plugin/rack.rb:54:in call&#39;监狱长(1.0.6)   lib / warden / manager.rb:35:in call' warden (1.0.6) lib/warden/manager.rb:34:in catch&#39;监狱长(1.0.6)   lib / warden / manager.rb:34:in call' actionpack (3.0.20) lib/action_dispatch/middleware/best_standards_support.rb:17:in来电&#39;   actionpack(3.0.20)lib / action_dispatch / middleware / head.rb:14:in   call' rack (1.2.7) lib/rack/methodoverride.rb:24:in呼叫&#39; 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 来电&#39; actionpack(3.0.20)   lib / action_dispatch / middleware / session / abstract_store.rb:149:call' actionpack (3.0.20) lib/action_dispatch/middleware/cookies.rb:302:in 来电&#39; 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 缓存&#39; 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 呼叫&#39; activerecord(3.0.20)   LIB / active_record / connection_adapters /抽象/ connection_pool.rb:354:在   call' actionpack (3.0.20) lib/action_dispatch/middleware/callbacks.rb:46:in呼叫&#39;的ActiveSupport   (3.0.20)lib / active_support / callbacks.rb:416:_run_call_callbacks' actionpack (3.0.20) lib/action_dispatch/middleware/callbacks.rb:44:in 来电&#39; rack(1.2.7)lib / rack / sendfile.rb:106:在call' actionpack (3.0.20) lib/action_dispatch/middleware/remote_ip.rb:48:in电话&#39;   actionpack(3.0.20)   lib / action_dispatch / middleware / show_exceptions.rb:47:in call' railties (3.0.20) lib/rails/rack/logger.rb:13:in来电&#39;机架(1.2.7)   lib / rack / runtime.rb:17:in call' activesupport (3.0.20) lib/active_support/cache/strategy/local_cache.rb:72:in call&#39;架   (1.2.7)lib / rack / lock.rb:13:in call' rack (1.2.7) lib/rack/lock.rb:13:in同步&#39;机架(1.2.7)   lib / rack / lock.rb:13:in call' actionpack (3.0.20) lib/action_dispatch/middleware/static.rb:30:in来电&#39; railties   (3.0.20)lib / rails / application.rb:168:在call' railties (3.0.20) lib/rails/application.rb:77:in发送&#39;铁路(3.0.20)   lib / rails / application.rb:77:在method_missing' railties (3.0.20) lib/rails/rack/log_tailer.rb:14:in电话&#39;机架(1.2.7)   lib / rack / content_length.rb:13:in call' rack (1.2.7) lib/rack/handler/webrick.rb:52:in service&#39;   /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 运行&#39;   /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 开始&#39;   /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 开始&#39;   /home/vasu/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:92:in   each' /home/vasu/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:92:in 开始&#39;   /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 开始&#39; rack(1.2.7)lib / rack / handler / webrick.rb:13:in run' rack (1.2.7) lib/rack/server.rb:217:in start&#39;铁路(3.0.20)   lib / rails / commands / server.rb:65:在start' railties (3.0.20) lib/rails/commands.rb:30 railties (3.0.20) lib/rails/commands.rb:27:in 点击&#39; railties(3.0.20)lib / rails / commands.rb:27 script / rails:6:in   `需要&#39;脚本/轨道:6

1 个答案:

答案 0 :(得分:2)

我看到的问题是GroupLink

中的方法
 def text
  self.text
 end

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