hi,
i want to pass the data between the controller,
Eg:
def a
num = 10
print num
end
def b
print num
end
if i load the b i want to get 10, how to do this? I tried to return
the num that dint work. how to do this?
–
regards,
|Prashanth|
hi,
i want to pass the data between the controller,
Eg:
def a
num = 10
print num
end
def b
print num
end
if i load the b i want to get 10, how to do this? I tried to return
the num that dint work. how to do this?
–
regards,
|Prashanth|
…there may be simpler way, but the first most appropriate thing that
pops into my mind is creating a module and including the module in both
controllers as such:
====== controllers/one_controller.rb ========
class OneController
include MyModule
def a
print_num
end
end
====== controllers/two_controller.rb ========
class TwoController
include MyModule
def b
print_num
end
end
====== lib/my_module.rb ========
class MyModule
def print_num
n=10
print n
end
both actions return ‘10’:
domain.com/one/a
domain.com/two/b
hth
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs