新しい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:in
add_on_blank'activemodel(3.0.20)lib / active_model / errors.rb:223:ineach' activemodel (3.0.20) lib/active_model/errors.rb:223:in
add_on_blank' activemodel(3.0.20)lib / active_model / validations / present.rb :9:invalidate' activesupport (3.0.20) lib/active_support/callbacks.rb:315:in
send'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:inrun_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:inperform_validations' activerecord (3.0.20) lib/active_record/validations.rb:43:in
save'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:intrace_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 savewith_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'approllback_active_record_state!' activerecord (3.0.20) lib/active_record/transactions.rb:239:in
/controllers/group_links_controller.rb:23:increate' 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:insend_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 :inprocess_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
send'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
send' activesupport(3.0.20)lib / active_support / callbacks.rb:94:inrun_callbacks' actionpack (3.0.20) lib/abstract_controller/callbacks.rb:17:in
process_action'actionpack(3.0.20)lib / action_controller / metal / rescue.rb:17:inprocess_action' actionpack (3.0.20) lib/action_controller/metal/instrumentation.rb:30:in
process_action'activesupport(3.0.20)lib / active_support / notifys.rb:52:ininstrument' activesupport (3.0.20) lib/active_support/notifications/instrumenter.rb:21:in
Instrument' activesupport(3.0.20)lib / active_support / notification.rb:52:ininstrument' actionpack (3.0.20) lib/action_controller/metal/instrumentation.rb:29:in
process_action'newrelic_rpm (3.3.4.1)lib / new_relic / agent / Instruments / rails3 / action_controller.rb:34:inprocess_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:intrace_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:inprocess' actionpack (3.0.20) lib/action_controller/metal.rb:138:in
dispatch' actionpack(3.0.20)lib / action_controller / metal / Rack_delegation.rb:14:indispatch' actionpack (3.0.20) lib/action_controller/metal.rb:178:in
action'actionpack(3.0.20)lib / action_dispatch / routing / route_set.rb:68:incall' actionpack (3.0.20) lib/action_dispatch/routing/route_set.rb:68:in
dispatch'actionpack(3.0.20)lib / action_dispatch / routing / route_set.rb:33:incall' 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:recognize' rack-mount (0.6.14) lib/rack/mount/code_generation.rb:131:in
inoptimized_each'rack-mount(0.6.14)lib / Rack / mount / code_generation.rb:92:inrecognize' rack-mount (0.6.14) lib/rack/mount/route_set.rb:139:in
call' actionpack(3.0.20)lib / action_dispatch / routing / route_set.rb:499:incall' newrelic_rpm (3.3.4.1) lib/new_relic/rack/browser_monitoring.rb:23:in
call '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:in
manager.rb:35:in catch'warden(call' warden (1.0.6) lib/warden/manager.rb:34:in
1.0.6)lib / warden /マネジャー。rb:34:incall' actionpack (3.0.20) lib/action_dispatch/middleware/best_standards_support.rb:17:in
call'actionpack(3.0.20)lib / action_dispatch / middleware / head.rb:14:incall' rack (1.2.7) lib/rack/methodoverride.rb:24:in
call' actionpack(3.0.20)lib / action_dispatch / middleware / params_parser.rb:21:incall' 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:incall' actionpack (3.0.20) lib/action_dispatch/middleware/cookies.rb:302:in
call'activerecord(3.0.20)lib / active_record / query_cache.rb:32:incall' 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:incache' 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:incall' actionpack (3.0.20) lib/action_dispatch/middleware/callbacks.rb:46:in
call' 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:incall' actionpack (3.0.20) lib/action_dispatch/middleware/remote_ip.rb:48:in
call'actionpack(3.0.20)lib / action_dispatch / middleware / show_exceptions.rb:47:incall' railties (3.0.20) lib/rails/rack/logger.rb:13:in
call'rack(1.2.7)lib / Rack / runtime.rb:17:incall' activesupport (3.0.20) lib/active_support/cache/strategy/local_cache.rb:72:in
call' Rack(1.2.7)lib / Rack / lock.rb:13:incall' rack (1.2.7) lib/rack/lock.rb:13:in
synchronize'rack(1.2.7)lib / Rack / lock.rb:13:incall' actionpack (3.0.20) lib/action_dispatch/middleware/static.rb:30:in
call'railties(3.0.20)lib / rails / application.rb:168:incall' railties (3.0.20) lib/rails/application.rb:77:in
send' railties(3.0.20)lib / rails / application.rb:77:in call'rackmethod_missing' railties (3.0.20) lib/rails/rack/log_tailer.rb:14:in
(1.2 .7)lib / Rack / content_length.rb:13:incall' rack (1.2.7) lib/rack/handler/webrick.rb:52:in
service'/home/vasu/.rvm /rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/httpserver.rb:104:inservice' /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:instart_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:ineach' /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:instart' /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:inrun' rack (1.2.7) lib/rack/server.rb:217:in
start'railties(3.0.20)lib / rails / Commands / server.rb:65:instart' 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