Virtual attributes in rails 4

前端 未结 1 1017
小鲜肉
小鲜肉 2021-02-08 13:29

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.         


        
相关标签:
1条回答
  • 2021-02-08 13:45

    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
    
    0 讨论(0)
提交回复
热议问题