L
L
lavezzi12015-08-27 09:24:53
Ruby on Rails
lavezzi1, 2015-08-27 09:24:53

How to render template from one controller to another?

There are two controllers and two templates respectively. But you need to output data from these two controllers to one page, say, to the template of the first controller, how to be? I tried render like here - rusrails.ru/layouts-and-rendering-in-rails that is, attach the second template to the first one =render "messages/message". It doesn't work because it needs methods from the second controller, undefined method for each errors rained down, and so on. What to do in this case? Merge controllers?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Palamarchuk, 2015-08-27
@lavezzi1

You are thinking a little wrong. In order for the controller to work, a request must come to it. Those. do ajax-request to it.

V
Vitaliy Orlov, 2015-08-27
@orlov0562

I'm not very good at ruby, but usually a controller action is a simple method that can be called anywhere.
for example there is

class controller_1 {
   public function action_1(){
       return $template_1->render()
   }
}

then you can do it like this:
class controller_2 {
   public function action_2(){
       $param = (new controller_1)->action_1();
       return $template_2->render($param)
   }
}

In order to understand how to solve this problem correctly, you can google the implementation of the PAC pattern (HMVC) for your jap.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question