okay, two very silly Ruby on Rails questions (I just started using RoR a
couple of hours ago).
Question 1:
hello.controller
class HelloController < ApplicationController
def index(incoming_value) @my_variable = incoming_value * 2
end
end
How do I call this method with say, the value of 5? I just want to send
a value as a parameter from index.rhtml and the controller to display
the value * 2. I’m a Java programmer so I’m completely lost here.
Question 2:
How would one go about to first create a input form which takes a
password and then if the user types the correct password, make the
controller redirect the user to page2.rhtml? I’m guessing I have to use
some sort of form helper here, but the concepts are all so new to me
that I’m more intimidated than motivated at the moment.
Since you’re new, please do yourself a favor and learn Ruby first: http://learnruby.com/sites.html has links to a few good tutorials (why’s
poignant guide is odd, but can be useful).
Then, once you’re somewhat comfortable with Ruby, start learning Rails: http://rails.homelinux.org/ is a great starter tutorial.
Also, if you can pick up books, look for the “Agile Development with
Rails”
and the “Pragmatic Programmers Guide to Ruby” books to get you started.
How do I call this method with say, the value of 5? I just want to send
a value as a parameter from index.rhtml and the controller to display
the value * 2. I’m a Java programmer so I’m completely lost here.
This should go as a helper instead. Helpers are methods (functions)
accessible from your views (rhtml files).
In your Hello Helper file you would have:
def times_two(incoming_value)
incoming_value * 2
end
In your Hello Controller, your index method would simply be:
def index
end
Which calls your hello/index.rthml file, where you would have:
A big thanks to the both of you, I’ll pick up a book and try to take a
couple of baby steps a day It’s just that nearly all Ruby tutorials
are based on building small CRUD applications so it’s hard to find bits
and pieces of information like this on the web.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.