Let’s say I did this:
script/generate controller home
And in the home controller made a the method..
def say
puts "You are here"
end
How would I call that method in the index.html.erb?
When learning ruby it just said to run the whatever.rb in the terminal
to run what ever code you wrote within that file. Just curious on how
that would work with rails.
I assume you have a rails server running?
Theres two possibilities, firstly you could make say a helper method in the controller by using:
in your controller.
Alternatively, the better solution would be move your say method to the home_helper(?).rb helper file.
you can call this by just using <% say %> in your view file.
Note that a
putswell put whatever is in your string to STDOUT, not output in your views, if all you wanna do is write a bit of text, you would be better off with just outputting a string and using the erb output mechanism in your view, e.g.application_helper.rb
index.html.erb
puts is very useful for unit test debugging where you wanna find out the contents of an object
Whereas if you want output to the log, you could do something like: