Rails参与! 错误(无法批量分配受保护的属性:用户)

我正在安装Engage!

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

我做的安装步骤:

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

现在,我可以去localhost:3000 /搞

做“耙路线”的结果的图片。它显示“参与/参与Engage :: Engine

这是出现的:

这是Engage的图片!论坛,我在其中输入了用于创建新主题的数据。这是右下角的“创建主题”提交按钮,我单击以在rails服务器控制台中获取错误。

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

“✓”,“authenticity_token” >“aRKQAwMsnc1DJJ62S6bb7EkhFkzuCDtNL0kV756LIP4 =”,“topic”=> {“style”=>“问题”,“标题”=>“ww”,“message”=>“www”,“follow”=>“1”}, “commit”=>“创建主题”}用户负载(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,2013年1月20日02:48:26 UTC +00:00],[“followers_count”,0 ],[“message”,“www”],[“private”,false],[“status”,“pending”],[“string”,nil],[“style”,“question”],[“ title“,”ww“],[”updated_at“,Sun,2013年1月20日02:48:26 UTC +00:00],[”user_id“,1],[”votes_count“,0]] Engage ::关注加载(0.3ms)SELECT“engage_followings”。* FROM“engage_followings”WHERE“engage_followings”。“topic_id”= 7 AND“engage_followings”。“user_id”= 1 LIMIT 1用户加载(0.2ms)SELECT“users”。* FROM “users”WHERE“users”。“id”= 1 LIMIT 1为 string 类型插入二进制数据列 token SQL(0.9ms)INSERT INTO“engage_followings”(“ created_at“,”token“,”topic_id“,”updated_at“,”user_id“)VALUES(?,?,?,?,?)[[”created_at“,Sun,2013年1月20日02:48:26 UTC +00 :00],[“token”,“5813db34aaedfa6226cf77b7a17d5dfbcf8d4560”],[“topic_id”,7],[“updated_at”,Sun,2013年1月20日02:48:26 UTC +00:00],[“user_id”,1 ]]恩加ge ::主题加载(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已完成500内部服务器错误71msActiveModel :: MassAssignmentSecurity :: Error(无法批量分配受保护的属性:user):activemodel(3.2.11)lib / active_model / mass_assignment_security / sanitizer.rb:48:in process_removed_attributes'activemodel(3.2.11)lib / active_model / mass_assignment_security / sanitizer.rb:20:in debug_protected_attribute_removal’activemodel(3.2.11)lib / active_model / mass_assignment_security /sanitizer.rb:12:在`sanitize'”>

所以我开始谷歌搜索,我看到这样的事情:

  • 无法批量分配受保护的属性:user
  • http://guides.rubyonrails.org/security.html#mass-assignment

我已将attr_accessible:user添加到我的用户模型,但这不起作用。

这是我的用户模型:

<img src="http://sofzh.miximages.com/sql/J1cti.png" alt="class User ‘UserResourceView’has_many:seen_resources,:through =>:resource_views,:source =>:resource has_many:evaluation, class_name:“RSEvaluation”,如:source has_reputation:votes,source:{reputation :: votes,of :: resources},aggregated_by :: sum has_reputation:karma,:source => {:reputationde ::::::: =>:resources} def voted_for?(resource)evaluations.where(target_type:resource.class,target_id:resource.id).present? end def recent_viewed_resources seen_resources.order(’user_resource_views.created_at DESC’)end#包括默认设计模块。其他可用的是:#:token_authenticatable,:confirmmable,#:lockable,:timeoutable和:omniauthable devise:database_authenticatable,:registerable,:recoverable,:rememberable,:trackable,:validatable #startible(或protected)属性为您的模型attr_accessible :user_id,:email,:password,:password_confirmation,:remember_me #attr_accessible:title,:body end”>

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

我的目录列表:控制器,助手,模型和视图。这些都不是Engage特定的。我找不到Engage的控制器等等。它在宝石中。

有谁知道如何解决这一问题? 如果您需要任何其他信息,请告诉我,我将提供截图。

任何帮助是极大的赞赏。 谢谢!

编辑#1 – 添加应用程序控制器图片和完整堆栈跟踪

这是我唯一能看到Engage的地方! 在控制器中(我目前没有用户控制器)

<img src="http://sofzh.miximages.com/sql/VLaAa.png" alt="application_controller.rb文件。 class ApplicationController

这是完整的堆栈跟踪:

“✓”,“authenticity_token” >“aRKQAwMsnc1DJJ62S6bb7EkhFkzuCDtNL0kV756LIP4 =”,“topic”=> {“style”=>“问题”,“标题”=>“ww”,“message”=>“www”,“follow”=>“1”}, “commit”=>“创建主题”}用户负载(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,2013年1月20日02:48:26 UTC +00:00],[“followers_count”,0 ],[“message”,“www”],[“private”,false],[“status”,“pending”],[“string”,nil],[“style”,“question”],[“ title“,”ww“],[”updated_at“,Sun,2013年1月20日02:48:26 UTC +00:00],[”user_id“,1],[”votes_count“,0]] Engage ::关注加载(0.3ms)SELECT“engage_followings”。* FROM“engage_followings”WHERE“engage_followings”。“topic_id”= 7 AND“engage_followings”。“user_id”= 1 LIMIT 1用户加载(0.2ms)SELECT“users”。* FROM “users”WHERE“users”。“id”= 1 LIMIT 1为 string 类型插入二进制数据列 token SQL(0.9ms)INSERT INTO“engage_followings”(“ created_at“,”token“,”topic_id“,”updated_at“,”user_id“)VALUES(?,?,?,?,?)[[”created_at“,Sun,2013年1月20日02:48:26 UTC +00 :00],[“token”,“5813db34aaedfa6226cf77b7a17d5dfbcf8d4560”],[“topic_id”,7],[“updated_at”,Sun,2013年1月20日02:48:26 UTC +00:00],[“user_id”,1 ]]恩加ge ::主题加载(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在71ms内完成500内部服务器错误”><img src="http://sofzh.miximages.com/sql/71Wwi.png" alt="SQL(0.9ms)INSERT INTO“engage_followings”(“created_at”,“token”,“topic_id”,“updated_at”,“user_id”)VALUES(?,?,?,?,?)[[“created_at”,Sun ,2013年1月20日02:48:26 UTC +00:00],[“令牌”,“5813db34aaedfa6226cf77b7a17d5dfbcf8d4560”],[“topic_id”,7],[“updated_at”,Sun,2013年1月20日02:48:26 UTC +00:00],[“user_id”,1]] Engage ::主题加载(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(选择“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已完成500内部服务器错误71ms ActiveModel :: MassAssignmentSecurity :: Error(无法进行质量分配保护attributes:user):activemodel(3.2.11)lib / active_model / mass_assignment_security / sanitizer.r b:48:在 process_removed_attributes'activemodel(3.2.11)lib / active_model / mass_assignment_security / sanitizer.rb:20:in debug_protected_attribute_removal’activemodel(3.2.11)lib / active_model / mass_assignment_security / sanitizer.rb :12:在 sanitize'activemodel(3.2.11)lib / active_model / mass_assignment_security.rb:230:in sanitize_for_mass_assignment’activerecord(3.2.11)lib / active_record / attribute_assignment.rb:75:in assign_attributes'activerecord(3.2.11)lib / active_record / base.rb:497:in initialize’activerecord(3.2.11)lib / active_record / reflection.rb:183:in new'activerecord (3.2.11)lib / active_record / reflection.rb:183:in build_association’activerecord(3.2.11)lib / active_record / associations / association.rb:233:in build_record'activerecord(3.2。 11)lib / active_record / associations / collection_association.rb:434:在块中的create_record’activerecord(3.2.11)lib / active_record / associations / collection_association.rb:14 9:在事务’activerecord(3.2.11)中的块中lib / active_record / connection_adapters / abstract / database_statements.rb:192:in transaction’activerecord(3.2.11)lib / active_record / transactions.rb :208:在 transaction'activerecord(3.2.11)lib / active_record / associations / collection_association.rb:148:in transaction’activerecord(3.2.11)lib / active_record / associations / collection_association.rb: 433:在 create_record'activerecord(3.2.11)lib / active_record / associations / collection_association.rb:119:in create’activerecord(3.2.11)lib / active_record / associations / collection_proxy.rb:46 :在 create'contagecsm(1.0.8)app / controllers / engage / topics_controller.rb:46:in create’actionpack(3.2.11)lib / action_controller / metal / implicit_render.rb:4:在 send_action'actionpack(3.2.11)lib / abstract_controller / base.rb:167:in process_action’actionpack(3.2.11)lib / action_controller / metal / rendering.rb:10:in process_action'actionpa ck(3.2.11)lib / abstract_controller / callbacks.rb:18:在块中的process_action’activesupport(3.2.11)lib / active_support / callbacks.rb:426:在`block in _run__2010401100414174750__process_action__2035169522325419882__callbacks'”>

<img src="http://sofzh.miximages.com/sql/cFkC0.png" alt="activesupport(3.2.11)lib / active_support / callbacks.rb:215:在_conditional_callback_around_4085中的块中'activesupport(3.2.11)lib / active_support / callbacks.rb:326:在中’activesupport(3.2) .11)lib / active_support / callbacks.rb:310:在 _callback_around_127'activesupport(3.2.11)lib / active_support / callbacks.rb:214:in _conditional_callback_around_4085’activesupport(3.2.11)lib / active_support / callbacks.rb:414:在 _run__2010401100414174750__process_action__2035169522325419882__callbacks'activesupport(3.2.11)lib / active_support / callbacks.rb:405:in __ run_callback’activesupport(3.2.11)lib / active_support / callbacks.rb :385:在 _run_process_action_callbacks'activesupport(3.2.11)lib / active_support / callbacks.rb:81:in run_callbacks’actionpack(3.2.11)lib / abstract_controller / callbacks.rb:17:in process_action'actionpack(3.2.11)lib / action_controller / metal / rescue.rb:29:in process_action’actionpack(3.2.11)lib / action _controller / metal / instrumentation.rb:30:在process_action中的块'activesupport(3.2.11)lib / active_support / notifications.rb:123:在仪器'activesupport(3.2.11)lib中的块中/active_support/notifications/instrumenter.rb:20:in instrument'activesupport(3.2.11)lib / active_support / notifications.rb:123:in instrument’actionpack(3.2.11)lib / action_controller / metal / instrumentation.rb:29:在 process_action'actionpack(3.2.11)lib / action_controller / metal / params_wrapper.rb:207:in process_action’activerecord(3.2.11)lib / active_record / railties /controller_runtime.rb:18:in process_action'actionpack(3.2.11)lib / abstract_controller / base.rb:121:in process’actionpack(3.2.11)lib / abstract_controller / rendering.rb: 45:在进程'actionpack(3.2.11)lib / action_controller / metal.rb:203:in dispatch’actionpack(3.2.11)lib / action_controller / metal / rack_delegation.rb:14:in dispatch'actionpack(3.2.11)lib / action_control ler / metal.rb:246:in block in action’actionpack(3.2.11)lib / action_dispatch / routing / route_set.rb:73:in call'actionpack(3.2.11)lib / action_dispatch /routing/route_set.rb:73:indispatch’actionpack(3.2.11)lib / action_dispatch / routing / route_set.rb:36:in call'travel(1.0.4)lib / journey / router.rb:68:在块中调用’journey(1.0.4)lib / journey / router.rb:56:在中每个'旅程(1.0.4)lib / journey / router.rb :56:in call’actionpack(3.2.11)lib / action_dispatch / routing / route_set.rb:601:in call'railties(3.2.11)lib / rails / engine.rb:479:在中调用’railties(3.2.11)lib / rails / railtie / configurable.rb:30:in method_missing'travel(1.0.4)lib / journey / router.rb:68:in block in call’travel(1.0.4)lib / journey / router.rb:56:in each'travel(1.0.4)lib / journey / router.rb:56:in call ‘actionpack(3.2.11)lib / action_dispatch / routing / route_set.rb:601:in call'warden(1.2.1)lib / warden / manager.rb:35:in bloc k in call’warden(1.2.1)lib / warden / manager.rb:34:in catch'warden(1.2.1)lib / warden / manager.rb:34:in call’actionpack (3.2.11)lib / action_dispatch / middleware / best_standards_support.rb:17:in call' rack(1.4.3)lib / rack / etag.rb:23:in call’rack(1.4。 3)lib / rack / conditionalget.rb:35:在中调用'actionpack(3.2.11)lib / action_dispatch / middleware / head.rb:14:in call’actionpack(3.2.11)lib /action_dispatch/middleware/params_parser.rb:21:in`call'”>

<img src="http://sofzh.miximages.com/sql/4ZkJI.png" alt="actionpack(3.2.11)lib / action_dispatch / middleware / flash.rb:242:在 call'cham(1.4.3)lib / rack / session / abstract / id.rb:210:in context ‘rack(1.4.3)lib / rack / session / abstract / id.rb:205:在 call'actionpack(3.2.11)lib / action_dispatch / middleware / cookies.rb:341:in 调用’activerecord(3.2.11)lib / active_record / query_cache.rb:64:in call'activerecord(3.2.11)lib / active_record / connection_adapters / abstract / connection_pool.rb:479:in call ‘actionpack(3.2.11)lib / action_dispatch / middleware / callbacks.rb:28:in block in call'activesupport(3.2.11)lib / active_support / callbacks.rb:405:in _run__4377122496359715927__call__4128007891844716680__callbacks’ activesupport(3.2.11)lib / active_support / callbacks.rb:405:在 __ run_callback'activesupport(3.2.11)lib / active_support / callbacks.rb:385:in _run_call_callbacks’activesupport(3.2.11) )lib / active_support / callbacks.rb:81:在 run_callbacks'actionpack(3.2.11)lib / action_dispatch中/middleware/callbacks.rb:27:incall’actionpack(3.2.11)lib / action_dispatch / middleware / reloader.rb:65:in call'actionpack(3.2.11)lib / action_dispatch / middleware / remote_ip.rb:31:in call’actionpack(3.2.11)lib / action_dispatch / middleware / debug_exceptions.rb:16:in call'actionpack(3.2.11)lib / action_dispatch / middleware /show_exceptions.rb:56:incall’railties(3.2.11)lib / rails / rack / logger.rb:32:in call_app'railties(3.2.11)lib / rails / rack / logger.rb:16:在块中调用’activesupport(3.2.11)lib / active_support / tagged_logging.rb:22:in tagged'railties(3.2.11)lib / rails / rack / logger .rb:16:in call’actionpack(3.2.11)lib / action_dispatch / middleware / request_id.rb:22:in call'cham(1.4.3)lib / rack / methodoverride.rb: 21:在中调用’rack(1.4.3)lib / rack / runtime.rb:17:在中调用'activesupport(3.2.11)lib / active_support / cache / strategy / local_cache.rb:72 :在中调用’rack(1.4.3)lib / rack / lock.rb:15:in 调用'actionpack(3.2.11)lib / action_dispatch / middleware / static.rb:62:in call’railties(3.2.11)lib / rails / engine.rb:479:in call'railties( 3.2.11)lib / rails / application.rb:223:在中调用’rack(1.4.3)lib / rack / content_length.rb:14:在中调用'railties(3.2.11)lib /rails/rack/log_tailer.rb:17:incall’ rack(1.4.3)lib / rack / handler / webrick.rb:59:in service'/Users/johndoe/.rbenv/ versions / 1.9.3-p327-perf / lib / ruby​​ / 1.9.1 / webrick / httpserver.rb:138:in service’/Users/johndoe/.rbenv/versions/1.9.3-p327-perf /lib/ruby/1.9.1/webrick/httpserver.rb:94:in run'/Users/johndoe/.rbenv/versions/1.9.3-p327-perf/lib/ruby/1.9.1/webrick /server.rb:191:in block in start_thread'”>

编辑#2 – 添加参与环境:

此外,我们安装了Devise(和我相信的OmniAuth ……)。 因此,我们有“current_user”,但我不知道我们是否有“用户名”或“电子邮件”方法,除非这是标准的Devise或其他东西 : 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之一! 开发者在这里 我可以看到Engage有两个问题! 如上所述。

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

第二个(主题实际上没有显示在索引页面上的事实)与cancan gem中的更改相关联。 我们仍然需要找出解决此问题的最佳方法,但快速解决方法是将cancan版本锁定在Gemfile中,如下所示: gem 'cancan', '1.6.7'

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

干杯!

根据所提供的信息,我担心我不知道发生了什么,但我可以帮助解释一下你所得到的错误。

跟踪中的最后一个非库行是:

engagecsm(1.0.8)app / controllers / engage / topics_controller.rb:46:在`create’中

此代码可能位于您的默认gem路径中。 如果你在* nix上,可能是/usr/lib/ruby/gems/home/user_name/.gem/ruby

有时在处理该行代码时,它会遇到质量分配安全性错误。

它可能会帮助您查看该行代码以查看它所遇到的模型。 请勿在此处发布该行代码。 Engage的许可证! 似乎不是标准的开源软件之一,如果您在此处发布,则可能违反了许可证。 我可能错了,但比抱歉更安全。

有两个变量可以通过质量分配安全性来解决您的问题。 它们是属性和角色。 将attr_accessible :user添加到适当的模型只有在他们使用默认角色时才有帮助。 如果他们使用:admin角色,那么您需要添加attr_accessible :user, as: :admin 。 我不认为您的User模型具有以下属性:user因此可能需要将其添加到其他位置。

如果我不得不猜测你做错了什么,我想你可能已经遵循了安全指南:

http://guides.rubyonrails.org/security.html

在该指南中,他们建议将配置设置为默认情况下将所有内容列入白名单。

 config.active_record.whitelist_attributes = true 

如果你这样做并参与! 不是用MassAssignment支持写的,这可以解释你所看到的错误。

对不起我无法确切地解释你的问题,但我希望它有所帮助。

看着你 堆栈跟踪 您的问题出现在topices_controller中 – 因此可能意味着您需要将:user_id添加到Engage/Topic模型中的attr_accessible

我需要将以下行添加到Engage / Vote Model

 attr_accessible :user 

现在它将说“主题成功创建”。

但是,我看不到列出的主题。 但是,我相信我已经完成了这部分问题。 我去的时候能看到这个话题

 http://localhost:3000/engage/topics/1