I understand that the application_controller will produce variable values for an entire application but have never applied that knowledge. There is a variable that comes up in most of my controllers… @qs for the number of questions. The following code is not working.
application_controller:
def qs
if current_user.sec_paid and current_user.min_paid
@qs = 36
elsif current_user.sec_paid
@qs = 25
else
@qs = 5
end
end
applets_controller:
@strengths = Strength.where("position <= ?", @qs).order("position")
applet1.html.erb:
<%=@qs.to_i%>
The output to a view file is just a way to test for the value of the variable and will be removed. Currently it produces a zero.
Any help is appreciated. Specific changes to my code is most appreciated.
Use
before_filter :qsin your ApplicationControler (or in those controllers it is needed) to invoke theqsmethod on every call. In this way the@qsvariable will be initialized.