Sunday, 15 February 2015

activerecord - update instance variable without updating the model rails -


I have the following model ...

  ItemAttribute (id: integer, name: String Kent: integer)  

In my controller I want to set a custom amount for counting that I can use within my view ...

  @building = ItemAttribute.find_by_name ("wall") # updates the following line of code as well as the example variable (which I do not want) @ building.update_attribute (: count, 10) #The following line of code Not updated Dal (desired), but the value is also reset to see the model's price (not want) ... @ buildings.find_by_name ( "wall"). Count = 10  

I'm using a counting feature in the loop in the view. The example of the wall is a special case, which is why I want to update this scene only in the scene I am

You can simply set an example variable in the controller and see it in that view.

  @Billing = itemattribute.find_by_name ("wall") @count = 10  

Then this example variable in your view access number @for just request Remains, and available for controller and view.

Make sure that your last line is trying to do, it is specifying 10 to calculate the list of active record objects.

To get 10 walls

  @ building = building.find_bie_name ("wall"). Limit (10)  

To get buildings where name == 'wall' and counting == 10

@ Buildings = building Where (name: "wall", count: 10)

No comments:

Post a Comment