How can I use virtual attributes(getter, setter) in rails 4, as 'attr_accessible' removed.
I am getting issue, here
def tags_list
@tags = self.tags.collect(&:name).join(', ')
end
I can reach above method, but not able to reach setter below, when trying to update/create.
def tags_list=(tags)
@tags = tags
end
Using virtual attributes in Rails 4 pretty much the same as with attr_accessible. You just have to add your virtual attribute to the permitted params in your controller (instead of attr_accessible), then add the getter and setter methods as usual in your model.
# your_controller.rb
private
def your_model_params
params.require(:your_model_name).permit(:tags_list)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With