I believe that You cannot call a controller model from another
controller in this way. If you need to do this it probably means that
the method should be in a model or in a module in the lib directory.
Or are you actually trying to redirect to a different action rather
than just call a method?
Sorry I misread the question and the reply above is rubbish anyway. I
thought you were wanting to call a controller method from another
controller. I must remember to engage brain before typing.
In check1.rb //model
def check?
self.name="karthik"
I think that should be self.name == "Karthik"
end
when i call from controller say check2controller.rb //different controller
i am calling as
check1=check1.new
check1.check? //returns true or false
i need to pass karthik as paramater to check?in check1.rb
so that it will return true or false
Please guide me how to do
--
def check?( a_name )
self.name == a_name
end
Then check1.check?( "karthik" )
If you call it immediately after check1.new then the name will always
be the default one for the name attribute of course. check1.check?(
"karthik" ) means hey object check1, is your name karthik?
There are a lot of mistakes (bug) in your code, but I think philosophically too you are wrong.
Firstly, you have “=” instead of “==” in your check? method. And if the word “karthik” is constant you don’t need to pass it. I think this solves your problem.
But please do read some detailed tutorial or preferably a book on rails, because I think you are missing too many points here.
Karthik, I have a two suggestions which I would like you consider very
seriously.
1. Get hold of the Pragmatic Bookshelf book Programming Ruby: The
Pragmatic Programmer's Guide, downloadable as an e-book. Spend a week
working through it till you have a good grasp of Ruby.
2. Get the book Agile Web Development with Rails, 3rd Edition and
spend another week (or more) working through that to give you a good
grasp of Rails.
This may seem like a lot of wasted time but in the long run it will
save you (and us) time and effort and will allow you develop reliable
applications much more effectively than you can at the moment.