Disclaimer: I’m a rails n00b. I’m playing around with a simple helper function that isn’t doing what I want it to do.
- I have a model called ‘webform’ with a few text fields (name, address, etc)
- I’m trying to use a helper function to test an if statement (i.e. ‘is the :address == ’10’)
-
Here’s the helper function
def webforms_helper if :address == 10 print "Address is 10" else print "Address is not 10" end end -
In my ‘show’ view, I have incorporated the helper function
<%= webforms_helper %> - I load the web app, get no errors — though, it doesn’t print out ‘Address is 10’ or ‘Address is not 10’
-
I’ve also had no success using puts (and checking the console) instead of print
-
Any thoughts? I apologize for the novice question 😉
First, a proper helper would look like this:
Then in your controller:
Then in your view:
So if the view were rendered in response to a form submit, and the form has the following:
And when the user filled out the form and put the string ’10’ as the address, ‘Address is 10’ would be generated in your view.