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

モデルの関係は1対多の関連です。

 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_linkではなくgroup_linksとして誤って作成したときに始まりました。そのため、移行をロールバックしてモデルを破棄し、正しい名前で再作成しました。この変更を行った後、このエラーがスローされ始めました(group_linksモデルを使用して新しいグループリンクを正しく作成していましたが、予想どおり、ルートは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 / present.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: with_transaction_returning_status' activerecord (3.0.20) lib/active_record/connection_adapters/abstract/database_statements.rb:139:in トランザクション内' 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 トランザクション内'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 save with_transaction_returning_status' activerecord (3.0.20) lib/active_record/transactions.rb:240:in' activerecord(3.0.20)lib / active_record / transaction.rb:251:in save'app rollback_active_record_state!' activerecord (3.0.20) lib/active_record/transactions.rb:239:in/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:insend'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:insend' 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 / notifys.rb:52:in instrument' activesupport (3.0.20) lib/active_support/notifications/instrumenter.rb:21:inInstrument' activesupport(3.0.20)lib / active_support / notification.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 / Instruments / 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 / Instruments / rails3 / action_controller.rb:33: のprocess_action' actionpack (3.0.20) lib/abstract_controller/base.rb:119:inプロセス'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: recognize' rack-mount (0.6.14) lib/rack/mount/code_generation.rb:131:ininoptimized_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(1.0.6)lib / warden / call' sass (3.2.5) lib/sass/./sass/plugin/rack.rb:54:inmanager.rb:35:in catch'warden( call' warden (1.0.6) lib/warden/manager.rb:34:in1.0.6)lib / warden /マネジャー。rb:34:incall' 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 call'rack _run_call_callbacks' actionpack (3.0.20) lib/action_dispatch/middleware/callbacks.rb:44:in (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 call'rack method_missing' railties (3.0.20) lib/rails/rack/log_tailer.rb:14:in(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 ' start_thread' /home/vasu/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:162:in /home/vasu/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:173:instart'/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:in each' /home/vasu/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:92:in start' /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'ラック(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: `require'スクリプト/rails:6

4

1 に答える 1

2

私が見る問題は、の方法ですGroupLink

 def text
  self.text
 end

text自分自身を呼び出すだけのメソッドを定義しています。このメソッドを削除してみてください。

于 2013-03-20T14:06:35.633 に答える