Am new to ROR and need immediate help in my wotk. I have a
controller.rb .In the 'create' and 'update' and 'show' methods in the
controller i want to call a function defined in some other class.
This 'some other class' will have functions that will do the work i
need.
1.My problem is where do i store this class that i need. ?in
controllers or models ? or perhaps in some other location
2. How do i name it?
For eg if Class Tea is my class name then should i save it as tea.rb?
3. How do i use the methodsof this class in my controller?
is it like...
Tea::method_name
or Tea.method_name
4.Or is there any other different way to define my own methods and call
it inside the controlller.
Builders or promoters of ROR ,Please reply so that i can convince my
MGMT to use ROR
hold on a second. When you say "do the work you need", what exactly is
going to happen when you create/update/show. More to the point: why do
you need the function to be defined in some other class?
It would make sense just to define the method in the controller
itself, and then call it from within there. You might even want to use
a before_create -type callback.
It doesn't sound like you've really understood the MVC paradigm, nor
some of the basics about where things go in Rails. You might want to
take some time to read over the various guide floating around the web,
or look into the Agile Web Development with Rails book, before you
charge into trying to convince your management to use Rails.
Am new to ROR and need immediate help in my wotk. I have a
controller.rb .In the 'create' and 'update' and 'show' methods in the
controller i want to call a function defined in some other class.
This 'some other class' will have functions that will do the work i
need.
1.My problem is where do i store this class that i need. ?in
controllers or models ? or perhaps in some other location
2. How do i name it?
For eg if Class Tea is my class name then should i save it as tea.rb?
3. How do i use the methodsof this class in my controller?
is it like...
Tea::method_name
or Tea.method_name
4.Or is there any other different way to define my own methods and call
it inside the controlller.
call it tea.rb (filename doesn't really matter, and you can have more than once class per file) and put it in the lib folder railsroot/lib. Now in the calling file put require "tea" at the top (it doesn't have to be at the top, just so it runs before you use it). Alternatively place require "tea" in config/environment.rb at the bottom and it will be available everywhere in rails.
If your file looks like this:
class Tea
def drink(how_much)
end
end
you can do this:
tea = Tea.new
tea.drink(10)
whereas if it looks like this:
module Tea
class Teacup
def fill(with)
end
end
end
you have to do this:
cup = Tea::Teacup.new
cup.fill('milk')
Of course you'll need to read much more about ruby, and this is *ruby* not rails stuff.