Rails 4.0.0.beta 1 and Mongoid

孤人 提交于 2019-12-12 14:52:44

问题


I am just trying out Mongodb and the latest rails setup.

I am using Rails 4.0.0.beta 1, Ruby 2.0.0p0 and mongoid 4.0.0.

I have a problem: I can create and delete objects as expected but cannot update objects. No error is returned, and the development log shows the changed parameters are being passed correctly.

Has anyone else hit this issue?


回答1:


Digging deeper I see that mongoid 4.0.0 is still referencing moped 1.4.5, which officially only supports ruby versions upto 1.9.3.

The latest version of moped on github is 2.0.0, which works with ruby 2.0.0, but not yet published to the gem repositories.

Looks like I may have to wait for a while to try this combination.




回答2:


I've been able to perform CRUD operations - however right now in my controllers (just for testing/spike) I'm allowing all parameters through strong_parameters.

In my Gemfile I've got:

gem 'mongoid' , git: 'https://github.com/mongoid/mongoid.git'

and in controllers I've:

params.require(:foo).permit! # allows everything, and bad security!!!

See this railscast: (http://railscasts.com/episodes/400-what-s-new-in-rails-4) or the code: (https://github.com/railscasts/400-what-s-new-in-rails-4)

review the controller code on the changes with strong_parameters, as I think this is what's getting you with the silent fails on updates :)

And on one of my models there are some pretty deep has_many :foo, and foo has_many :bar and bar has_many :baz of which I have accepts_nested_attributes_for on each.

So just saying you may want to try things out a little more or perhaps there was an update to underlinings on mongoid between when you tried and when I have been.



来源:https://stackoverflow.com/questions/15793400/rails-4-0-0-beta-1-and-mongoid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!