当我尝试创建新的 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: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/ Presence.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:inwith_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:intransaction_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: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:inwith_transaction_returning_status' activerecord (3.0.20) lib/active_record/transactions.rb:240:in
save' activerecord (3.0.20) lib/active_record/transactions.rb:251:inrollback_active_record_state!' activerecord (3.0.20) lib/active_record/transactions.rb:239:in
save' app /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
发送'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: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/notifications.rb:52:ininstrument' activesupport (3.0.20) lib/active_support/notifications/instrumenter.rb:21:in
instrument' activesupport (3.0.20) lib/active_support/notifications.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/instrumentation/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/instrumentation/rails3/action_controller.rb:33: 在process_action' actionpack (3.0.20) lib/abstract_controller/base.rb:119:in
process' 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:inrecognize' rack-mount (0.6.14) lib/rack/mount/code_generation.rb:131:in
optimize_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'wardencall' sass (3.2.5) lib/sass/./sass/plugin/rack.rb:54:in
(1.0.6) lib/warden/manager.rb:35:incall' warden (1.0.6) lib/warden/manager.rb:34:in
catch'warden (1.0.6) lib/warden /经理。RB:34:在call' 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_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: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:inmethod_missing' railties (3.0.20) lib/rails/rack/log_tailer.rb:14:in
call' rack (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 '/home/vasu/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:173:instart_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: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:在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:instart' /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: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:在“需要”脚本/rails:6