instance and class variables in rails controller

后端 未结 5 1435
一整个雨季
一整个雨季 2021-01-30 23:21

I\'m new to rails and ruby. I was studying the concept of class and instance variables. I understood the difference but when I tried it out using the controller in rails it got

5条回答
  •  北海茫月
    2021-01-30 23:39

    Declaring the @insworld within the class but not in the constructor or any of the instance methods sets @insworld scoped to the instance of the class itself.

    BooksController.instance_variable_get(:'@insworld')
    

    If you need the access to variable inside of your index method, consider defining it within the method instead.

提交回复
热议问题