best_in_place
best_in_place copied to clipboard
it is not working on non active record.
I saw the guide on github and tried like this.
v = 100
best_in_place v, :to_i, as: :input, url: set_stock_ice_cream_path(flavour: flavour, size: size)
but it shows error like this.
undefined method `model_name' for Fixnum:Class
When I set v like this,
v = "100"
undefined method `model_name' for String:Class
I guess best_in_place only expect model.
please check this.
Thanks.
@kikikiblue
Params:
object (Mandatory): The Object parameter represents the object itself you are about to modify
field (Mandatory): The field (passed as symbol) is the attribute of the Object you are going to display/edit.
the second param is the field
At least you should try adding ActiveModel::Model
to have a set a basic Rails conventions.
However, although I get it to render without errors, it shows up only in read-only mode. I do see the field value and the box around it when trying to edit, but it does not allow editing.
I am receiving this error also, trying to use best_in_place to edit a hash of key/value pairs. :+1:
utils.rb
def model_name_from_record_or_class(record_or_class)
(record_or_class.is_a?(Class) ? record_or_class : convert_to_model(record_or_class).class).model_name
end
I think here is the culprit. When trying to follow your Non Active Record example and use best in place on a string, String.is_a?(Class) returns false, but also cannot be converted to a model.
Having same issue trying to use a serialized jsonb column with best_in_place.
I get undefined method `model_name' for Hashie::Mash:Class
Happy to add a field to make sure bip always knows the appropriate model_name, but I think it would be easier if that field was possible to just apply to the instance rather than needing to be a class method response. e.g.
Now if you define a ({to_model:@model}) on a Hashie, it will display appropriately. Might be a useful one for the docs.