I have a model with serialized data and I want to edit this data using the best_in_place
gem. This isn't possible by default when using the best_in_place gem. How can this be done?
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- Json.NET deserializing contents of a JObject?
- Eager-loading association count with Arel (Rails 3
- Is there a way to remove IDV Tags from an AIFF fil
相关文章
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- how to call a active record named scope with a str
- serializing a list of objects into a file in java
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
- Rspec controller error expecting <“index”> but
It can be done by extending
method_missing
andrespond_to_missing?
to forward the requests to the serialized data. Lets say you have your serializedHash
indata
. In the class that's containing the serialized data you can for example use this code:Now you can access the object.data[:name] using the getter object.data_name and set value using the setter object.data_name="test". But to get this working using
best_in_place
you need to dynamicly add it to theattr_accessible
list. To do this you need to change the behavior of themass_assignment_authorizer
and make the object respond toaccessable_methods
with an array of method names that should be allowed to be edited like this:So in the View you can now call
To edit the serialized data of @object.data[:name]
// You can also do this for an array using the element index instead of the attribute name:
You dont need to change the rest of the code.