gpt4 book ai didi

sql - rails 参与!错误(无法批量分配 protected 属性 : user)

转载 作者:数据小太阳 更新时间:2023-10-29 08:50:26 27 4
gpt4 key购买 nike

我正在安装 Engage!

我按照此处的安装说明进行操作:http://engagecsm.com/readme

我做的安装步骤:

  1. 添加互动!到应用程序的 Gemfile:gem 'engagecsm'。
  2. 安装它:捆绑安装。
  3. 运行生成器:rails generate engage User。
  4. 运行迁移:rake db:migrate。

现在,我可以转到 localhost:3000/engage

Picture of the results of doing "rake routes". It displays "engage    /engage     Engage::Engine

这是显示的内容:

This is a picture of the Engage! forum, where I have entered data to be used in created a new topic. THere is a "Create Topic" submit button in the bottom right that I click to get the error in the rails server console.

现在,当我点击“创建主题”时,网站上没有任何反应。我查看我的 Rails 服务器控制台,我看到了这个:(更容易在此处查看 http://i.stack.imgur.com/xKBER.png ,在底部找到完整的堆栈跟踪)

Started POST "/engage/topics" for 127.0.0.1 at 2013-01-19 19:48:26 -0700 Processing by Engage::TopicsController#create as JS  Parameters: {"utf8"=>"✓", "authenticity_token"=>"aRKQAwMsnc1DJJ62S6bb7EkhFkzuCDtNL0kV756LIP4=", "topic"=>{"style"=>"question", "title"=>"ww", "message"=>"www", "follow"=>"1"}, "commit"=>"Create Topic"}  User Load (0.3ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1  Engage::UserProfile Load (0.4ms)  SELECT "engage_user_profiles".* FROM "engage_user_profiles" WHERE "engage_user_profiles"."user_id" = 1 LIMIT 1   (0.1ms)  begin transaction  Engage::UserProfile Load (0.3ms)  SELECT "engage_user_profiles".* FROM "engage_user_profiles" INNER JOIN "users" ON "engage_user_profiles"."user_id" = "users"."id" WHERE "users"."id" = 1 LIMIT 1  SQL (1.2ms)  INSERT INTO "engage_topics" ("comments_count", "created_at", "followers_count", "message", "private", "status", "string", "style", "title", "updated_at", "user_id", "votes_count") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)  [["comments_count", 0], ["created_at", Sun, 20 Jan 2013 02:48:26 UTC +00:00], ["followers_count", 0], ["message", "www"], ["private", false], ["status", "pending"], ["string", nil], ["style", "question"], ["title", "ww"], ["updated_at", Sun, 20 Jan 2013 02:48:26 UTC +00:00], ["user_id", 1], ["votes_count", 0]]  Engage::Following Load (0.3ms)  SELECT "engage_followings".* FROM "engage_followings" WHERE "engage_followings"."topic_id" = 7 AND "engage_followings"."user_id" = 1 LIMIT 1  User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1 Binary data inserted for <code>string</code> type on column <code>token</code>  SQL (0.9ms)  INSERT INTO "engage_followings" ("created_at", "token", "topic_id", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?)  [["created_at", Sun, 20 Jan 2013 02:48:26 UTC +00:00], ["token", "5813db34aaedfa6226cf77b7a17d5dfbcf8d4560"], ["topic_id", 7], ["updated_at", Sun, 20 Jan 2013 02:48:26 UTC +00:00], ["user_id", 1]]  Engage::Topic Load (0.2ms)  SELECT "engage_topics".* FROM "engage_topics" WHERE "engage_topics"."id" = 7 ORDER BY created_at DESC LIMIT 1  SQL (0.8ms)  UPDATE "engage_topics" SET "followers_count" = COALESCE("followers_count", 0) + 1 WHERE "engage_topics"."id" IN (SELECT "engage_topics"."id" FROM "engage_topics" WHERE "engage_topics"."id" = 7 ORDER BY created_at DESC)   (3.8ms)  commit transaction   (0.1ms)  begin transaction   (0.1ms)  rollback transaction Completed 500 Internal Server Error in 71msActiveModel::MassAssignmentSecurity::Error (Can't mass-assign protected attributes: user):  activemodel (3.2.11) lib/active_model/mass_assignment_security/sanitizer.rb:48:in <code>process_removed_attributes'  activemodel (3.2.11) lib/active_model/mass_assignment_security/sanitizer.rb:20:in</code>debug_protected_attribute_removal'  activemodel (3.2.11) lib/active_model/mass_assignment_security/sanitizer.rb:12:in `sanitize'

所以我开始谷歌搜索,我看到了这样的东西:

我已经将 attr_accessible :user 添加到我的 User 模型中,但这没有用。

这是我的用户模型:

class User < ActiveRecord::Base  include Engage::Extensions::User  has_many :resources  has_many :resource_views, :class_name => 'UserResourceView'  has_many :viewed_resources, :through => :resource_views, :source => :resource    has_many :evaluations, class_name: "RSEvaluation", as: :source  has_reputation :votes, source: {reputation: :votes, of: :resources}, aggregated_by: :sum  has_reputation :karma,      :source => { :reputation => :votes, :of => :resources }  def voted_for?(resource)    evaluations.where(target_type: resource.class, target_id: resource.id).present?  end    def recently_viewed_resources    viewed_resources.order('user_resource_views.created_at DESC')  end  # Include default devise modules. Others available are:  # :token_authenticatable, :confirmable,  # :lockable, :timeoutable and :omniauthable  devise :database_authenticatable, :registerable,         :recoverable, :rememberable, :trackable, :validatable  # Setup accessible (or protected) attributes for your model  attr_accessible :user_id, :email, :password, :password_confirmation, :remember_me  # attr_accessible :title, :body end

此外,我看不到我如何访问 Engage 模型等,请看这里是我的目录:

List of my directory: Controllers, Helpers, Models and Views. None of which is Engage specific. I couldn't find where Engage's controllers and such was. It is in the gem.

有人知道怎么解决吗?如果您需要任何其他信息,请告诉我,我会提供屏幕截图。

非常感谢任何帮助。谢谢!

编辑 #1 - 添加应用程序 Controller 图片和完整堆栈跟踪

这是我唯一可以看到 Engage 内容的地方!在 Controller 中(此时我没有用户 Controller )

application_controller.rb file. class ApplicationController < ActionController::Base include Engage::Extensions::Helpers  protect_from_forgery  end

这是完整的堆栈跟踪:

Started POST "/engage/topics" for 127.0.0.1 at 2013-01-19 19:48:26 -0700 Processing by Engage::TopicsController#create as JS  Parameters: {"utf8"=>"✓", "authenticity_token"=>"aRKQAwMsnc1DJJ62S6bb7EkhFkzuCDtNL0kV756LIP4=", "topic"=>{"style"=>"question", "title"=>"ww", "message"=>"www", "follow"=>"1"}, "commit"=>"Create Topic"}  User Load (0.3ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1  Engage::UserProfile Load (0.4ms)  SELECT "engage_user_profiles".* FROM "engage_user_profiles" WHERE "engage_user_profiles"."user_id" = 1 LIMIT 1   (0.1ms)  begin transaction  Engage::UserProfile Load (0.3ms)  SELECT "engage_user_profiles".* FROM "engage_user_profiles" INNER JOIN "users" ON "engage_user_profiles"."user_id" = "users"."id" WHERE "users"."id" = 1 LIMIT 1  SQL (1.2ms)  INSERT INTO "engage_topics" ("comments_count", "created_at", "followers_count", "message", "private", "status", "string", "style", "title", "updated_at", "user_id", "votes_count") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)  [["comments_count", 0], ["created_at", Sun, 20 Jan 2013 02:48:26 UTC +00:00], ["followers_count", 0], ["message", "www"], ["private", false], ["status", "pending"], ["string", nil], ["style", "question"], ["title", "ww"], ["updated_at", Sun, 20 Jan 2013 02:48:26 UTC +00:00], ["user_id", 1], ["votes_count", 0]]  Engage::Following Load (0.3ms)  SELECT "engage_followings".* FROM "engage_followings" WHERE "engage_followings"."topic_id" = 7 AND "engage_followings"."user_id" = 1 LIMIT 1  User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1 Binary data inserted for <code>string</code> type on column <code>token</code>  SQL (0.9ms)  INSERT INTO "engage_followings" ("created_at", "token", "topic_id", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?)  [["created_at", Sun, 20 Jan 2013 02:48:26 UTC +00:00], ["token", "5813db34aaedfa6226cf77b7a17d5dfbcf8d4560"], ["topic_id", 7], ["updated_at", Sun, 20 Jan 2013 02:48:26 UTC +00:00], ["user_id", 1]]  Engage::Topic Load (0.2ms)  SELECT "engage_topics".* FROM "engage_topics" WHERE "engage_topics"."id" = 7 ORDER BY created_at DESC LIMIT 1  SQL (0.8ms)  UPDATE "engage_topics" SET "followers_count" = COALESCE("followers_count", 0) + 1 WHERE "engage_topics"."id" IN (SELECT "engage_topics"."id" FROM "engage_topics" WHERE "engage_topics"."id" = 7 ORDER BY created_at DESC)   (3.8ms)  commit transaction   (0.1ms)  begin transaction   (0.1ms)  rollback transaction Completed 500 Internal Server Error in 71ms SQL (0.9ms)  INSERT INTO "engage_followings" ("created_at", "token", "topic_id", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?)  [["created_at", Sun, 20 Jan 2013 02:48:26 UTC +00:00], ["token", "5813db34aaedfa6226cf77b7a17d5dfbcf8d4560"], ["topic_id", 7], ["updated_at", Sun, 20 Jan 2013 02:48:26 UTC +00:00], ["user_id", 1]]  Engage::Topic Load (0.2ms)  SELECT "engage_topics".* FROM "engage_topics" WHERE "engage_topics"."id" = 7 ORDER BY created_at DESC LIMIT 1  SQL (0.8ms)  UPDATE "engage_topics" SET "followers_count" = COALESCE("followers_count", 0) + 1 WHERE "engage_topics"."id" IN (SELECT "engage_topics"."id" FROM "engage_topics" WHERE "engage_topics"."id" = 7 ORDER BY created_at DESC)   (3.8ms)  commit transaction   (0.1ms)  begin transaction   (0.1ms)  rollback transaction Completed 500 Internal Server Error in 71ms ActiveModel::MassAssignmentSecurity::Error (Can't mass-assign protected attributes: user):  activemodel (3.2.11) lib/active_model/mass_assignment_security/sanitizer.rb:48:in <code>process_removed_attributes'  activemodel (3.2.11) lib/active_model/mass_assignment_security/sanitizer.rb:20:in</code>debug_protected_attribute_removal'  activemodel (3.2.11) lib/active_model/mass_assignment_security/sanitizer.rb:12:in <code>sanitize'  activemodel (3.2.11) lib/active_model/mass_assignment_security.rb:230:in</code>sanitize_for_mass_assignment'  activerecord (3.2.11) lib/active_record/attribute_assignment.rb:75:in <code>assign_attributes'  activerecord (3.2.11) lib/active_record/base.rb:497:in</code>initialize'  activerecord (3.2.11) lib/active_record/reflection.rb:183:in <code>new'  activerecord (3.2.11) lib/active_record/reflection.rb:183:in</code>build_association'  activerecord (3.2.11) lib/active_record/associations/association.rb:233:in <code>build_record'  activerecord (3.2.11) lib/active_record/associations/collection_association.rb:434:in</code>block in create_record'  activerecord (3.2.11) lib/active_record/associations/collection_association.rb:149:in <code>block in transaction'  activerecord (3.2.11) lib/active_record/connection_adapters/abstract/database_statements.rb:192:in</code>transaction'  activerecord (3.2.11) lib/active_record/transactions.rb:208:in <code>transaction'  activerecord (3.2.11) lib/active_record/associations/collection_association.rb:148:in</code>transaction'  activerecord (3.2.11) lib/active_record/associations/collection_association.rb:433:in <code>create_record'  activerecord (3.2.11) lib/active_record/associations/collection_association.rb:119:in</code>create'  activerecord (3.2.11) lib/active_record/associations/collection_proxy.rb:46:in <code>create'  engagecsm (1.0.8) app/controllers/engage/topics_controller.rb:46:in</code>create'  actionpack (3.2.11) lib/action_controller/metal/implicit_render.rb:4:in <code>send_action'  actionpack (3.2.11) lib/abstract_controller/base.rb:167:in</code>process_action'  actionpack (3.2.11) lib/action_controller/metal/rendering.rb:10:in <code>process_action'  actionpack (3.2.11) lib/abstract_controller/callbacks.rb:18:in</code>block in process_action'  activesupport (3.2.11) lib/active_support/callbacks.rb:426:in `block in _run__2010401100414174750__process_action__2035169522325419882__callbacks'

activesupport (3.2.11) lib/active_support/callbacks.rb:215:in <code>block in _conditional_callback_around_4085'  activesupport (3.2.11) lib/active_support/callbacks.rb:326:in</code>around'  activesupport (3.2.11) lib/active_support/callbacks.rb:310:in <code>_callback_around_127'  activesupport (3.2.11) lib/active_support/callbacks.rb:214:in</code>_conditional_callback_around_4085'  activesupport (3.2.11) lib/active_support/callbacks.rb:414:in <code>_run__2010401100414174750__process_action__2035169522325419882__callbacks'  activesupport (3.2.11) lib/active_support/callbacks.rb:405:in</code>__run_callback'  activesupport (3.2.11) lib/active_support/callbacks.rb:385:in <code>_run_process_action_callbacks'  activesupport (3.2.11) lib/active_support/callbacks.rb:81:in</code>run_callbacks'  actionpack (3.2.11) lib/abstract_controller/callbacks.rb:17:in <code>process_action'  actionpack (3.2.11) lib/action_controller/metal/rescue.rb:29:in</code>process_action'  actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:30:in <code>block in process_action'  activesupport (3.2.11) lib/active_support/notifications.rb:123:in</code>block in instrument'  activesupport (3.2.11) lib/active_support/notifications/instrumenter.rb:20:in <code>instrument'  activesupport (3.2.11) lib/active_support/notifications.rb:123:in</code>instrument'  actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:29:in <code>process_action'  actionpack (3.2.11) lib/action_controller/metal/params_wrapper.rb:207:in</code>process_action'  activerecord (3.2.11) lib/active_record/railties/controller_runtime.rb:18:in <code>process_action'  actionpack (3.2.11) lib/abstract_controller/base.rb:121:in</code>process'  actionpack (3.2.11) lib/abstract_controller/rendering.rb:45:in <code>process'  actionpack (3.2.11) lib/action_controller/metal.rb:203:in</code>dispatch'  actionpack (3.2.11) lib/action_controller/metal/rack_delegation.rb:14:in <code>dispatch'  actionpack (3.2.11) lib/action_controller/metal.rb:246:in</code>block in action'  actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:73:in <code>call'  actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:73:in</code>dispatch'  actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:36:in <code>call'  journey (1.0.4) lib/journey/router.rb:68:in</code>block in call'  journey (1.0.4) lib/journey/router.rb:56:in <code>each'  journey (1.0.4) lib/journey/router.rb:56:in</code>call'  actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:601:in <code>call'  railties (3.2.11) lib/rails/engine.rb:479:in</code>call'  railties (3.2.11) lib/rails/railtie/configurable.rb:30:in <code>method_missing'  journey (1.0.4) lib/journey/router.rb:68:in</code>block in call'  journey (1.0.4) lib/journey/router.rb:56:in <code>each'  journey (1.0.4) lib/journey/router.rb:56:in</code>call'actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:601:in <code>call'  warden (1.2.1) lib/warden/manager.rb:35:in</code>block in call'  warden (1.2.1) lib/warden/manager.rb:34:in <code>catch'  warden (1.2.1) lib/warden/manager.rb:34:in</code>call'  actionpack (3.2.11) lib/action_dispatch/middleware/best_standards_support.rb:17:in <code>call'  rack (1.4.3) lib/rack/etag.rb:23:in</code>call'  rack (1.4.3) lib/rack/conditionalget.rb:35:in <code>call'  actionpack (3.2.11) lib/action_dispatch/middleware/head.rb:14:in</code>call'  actionpack (3.2.11) lib/action_dispatch/middleware/params_parser.rb:21:in `call'

actionpack (3.2.11) lib/action_dispatch/middleware/flash.rb:242:in <code>call'  rack (1.4.3) lib/rack/session/abstract/id.rb:210:in</code>context'  rack (1.4.3) lib/rack/session/abstract/id.rb:205:in <code>call'  actionpack (3.2.11) lib/action_dispatch/middleware/cookies.rb:341:in</code>call'  activerecord (3.2.11) lib/active_record/query_cache.rb:64:in <code>call'  activerecord (3.2.11) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in</code>call'  actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:28:in <code>block in call'  activesupport (3.2.11) lib/active_support/callbacks.rb:405:in</code>_run__4377122496359715927__call__4128007891844716680__callbacks'  activesupport (3.2.11) lib/active_support/callbacks.rb:405:in <code>__run_callback'  activesupport (3.2.11) lib/active_support/callbacks.rb:385:in</code>_run_call_callbacks'  activesupport (3.2.11) lib/active_support/callbacks.rb:81:in <code>run_callbacks'  actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:27:in</code>call'  actionpack (3.2.11) lib/action_dispatch/middleware/reloader.rb:65:in <code>call'  actionpack (3.2.11) lib/action_dispatch/middleware/remote_ip.rb:31:in</code>call'  actionpack (3.2.11) lib/action_dispatch/middleware/debug_exceptions.rb:16:in <code>call'  actionpack (3.2.11) lib/action_dispatch/middleware/show_exceptions.rb:56:in</code>call'  railties (3.2.11) lib/rails/rack/logger.rb:32:in <code>call_app'  railties (3.2.11) lib/rails/rack/logger.rb:16:in</code>block in call'  activesupport (3.2.11) lib/active_support/tagged_logging.rb:22:in <code>tagged'  railties (3.2.11) lib/rails/rack/logger.rb:16:in</code>call'  actionpack (3.2.11) lib/action_dispatch/middleware/request_id.rb:22:in <code>call'  rack (1.4.3) lib/rack/methodoverride.rb:21:in</code>call'  rack (1.4.3) lib/rack/runtime.rb:17:in <code>call'  activesupport (3.2.11) lib/active_support/cache/strategy/local_cache.rb:72:in</code>call'  rack (1.4.3) lib/rack/lock.rb:15:in <code>call'  actionpack (3.2.11) lib/action_dispatch/middleware/static.rb:62:in</code>call'  railties (3.2.11) lib/rails/engine.rb:479:in <code>call'  railties (3.2.11) lib/rails/application.rb:223:in</code>call'  rack (1.4.3) lib/rack/content_length.rb:14:in <code>call'  railties (3.2.11) lib/rails/rack/log_tailer.rb:17:in</code>call'  rack (1.4.3) lib/rack/handler/webrick.rb:59:in <code>service' /Users/johndoe/.rbenv/versions/1.9.3-p327-perf/lib/ruby/1.9.1/webrick/httpserver.rb:138:in</code>service' /Users/johndoe/.rbenv/versions/1.9.3-p327-perf/lib/ruby/1.9.1/webrick/httpserver.rb:94:in <code>run'  /Users/johndoe/.rbenv/versions/1.9.3-p327-perf/lib/ruby/1.9.1/webrick/server.rb:191:in</code>block in start_thread'

编辑 #2 - 添加互动环境:

此外,我们还安装了 Devise(我相信还有 OmniAuth……)。因此,我们有“current_user”,但我不知道我们是否有“用户名”或“电子邮件”方法,除非它是 Devise 或其他东西的标准 This is the engage.rb file. Engage.configure do |config| config.layout = 'application' config.user_model = 'User' config.mailer_sender = 'engage@knowledgethief.com' config.internal_authentication = false config.current_user_method = Proc.new { current_user } config.login_link = { :path => :new_user_session_path, :opts => { :remote => true } } config.username_method = Proc.new { username } config.email_method = Proc.new { email } end

编辑 #3 - 正如 Geoff 所建议的,我查看了 topics_controller 的第 46 行。该行如下:

@topic.votes.create(:user => engage_current_user)

最佳答案

这是参与其中之一!开发人员在这里。我可以看到 Engage 有两个问题!如上所述。

我们已经找到第一个的解决方案(您使用 attr_accessible :user 解决的那个),所以期待 Rubygems 很快更新。

第二个(主题实际上并未显示在索引页上的事实)与 cancan gem 的变化有关。我们仍然需要找到解决这个问题的最佳方法,但一个快速的解决方法是将 cancan 版本锁定在 Gemfile 中,如下所示:gem 'cancan', '1.6.7'

我们会在 Rubygems 提供解决这些问题的更新时通知您。

干杯!

关于sql - rails 参与!错误(无法批量分配 protected 属性 : user),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14421250/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com