开发者

Passing data from one controller to another

开发者 https://www.devze.com 2023-03-25 13:32 出处:网络
I have a resource \'User\'. In it\'s controller there is an action \'choose\'. Index view is modified the way it is a form where you can choose some users. Pushing submit button invokes \'choose\' act

I have a resource 'User'. In it's controller there is an action 'choose'. Index view is modified the way it is a form where you can choose some users. Pushing submit button invokes 'choose' action from controller. After some processing in this action there is an array @users conta开发者_如何学Cining selected users' ids.

This array should be somehow passed to another controller. Let's say there is another resource 'JobToDo'. In the controller there would be an action 'assign_workers'. When this action is called the following algorithm should be done:

  • call assign_workers
  • call index of the User
  • in the displayed view you choose some users
  • you click 'submit' and therefore invoke choose action (array @users is created)
  • array @users is than passed to assign_workers <--- and this is my problem

I want this choosing to be universal and to work no matter which action from which controller calls it. I don't want to add other 'logic' every time I decide to use this choosing in a new situation.

We better assume that the the array @users is quite big.

Is it possible? Or maybe my idea isn't a good one and I should do it another way - than how?

Thanks in advance

Bye


Without knowing the ins and outs of your application my first recommendation would be to use the choose action to display the form assign workers. Otherwise you will need to store it in the db or the session, or include them in the url as parameters.

0

精彩评论

暂无评论...
验证码 换一张
取 消