samedi 27 juin 2015

Rails force instance variable declaration before use on view

Is it possible to force Ruby/Rails to throw an error when printing/using instance variables on a view that haven't been defined on controller

I'm declaring an instance variable on a Rails Controller and I'm printing its value on a View

def controller_action
    @some_data = "some value"
end

Then we know we can print its value on a view

<p>Some data has <%= @some_data %></p>

My problem is when doing mistakes on a view like this:

<p>Some data has <%= @somedata %></p>

Ruby won't complain and it's difficult to find those mistakes. This also applies for team development where some programmer can create an instance variable on a controller with one name and another programmer expects to print it on a view but accidentally uses other name.

Aucun commentaire:

Enregistrer un commentaire