Pieter Hugo
2012-Mar-08 11:47 UTC
Is there a way to redirect from one controller action to another without a server trip?
Hi I want one controller action to invoke another action in another controller, but I don''t want the overhead of a redirect_to response which then generates another request to the correct action and controller. Any suggestions? Pieter -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Loganathan Sellapa
2012-Mar-08 11:52 UTC
Re: Is there a way to redirect from one controller action to another without a server trip?
Create object for that controller then call.
class A
def a1
* invoke=B.new**
invoke.action(args)*
end
end
class B
def action(args)
something
end
end
regards,
Loganathan
On Thu, Mar 8, 2012 at 5:17 PM, Pieter Hugo
<lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:
> Hi
>
> I want one controller action to invoke another action in another
> controller, but I don''t want the overhead of a redirect_to
response
> which then generates another request to the correct action and
> controller. Any suggestions?
>
> Pieter
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
>
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Pieter Hugo
2012-Mar-08 11:55 UTC
Re: Is there a way to redirect from one controller action to another without a server trip?
something like render :controller => othercontroller, :action => :otheraction, :params => params ? (preserving the params would be a sweet bonus :) -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Loganathan Sellapa
2012-Mar-08 11:58 UTC
Re: Re: Is there a way to redirect from one controller action to another without a server trip?
On Thu, Mar 8, 2012 at 5:25 PM, Pieter Hugo <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> something like > > render :controller => othercontroller, :action => :otheraction, :params > => params >* Nope, I hope you cant call another controller action like this.*> > ? > > (preserving the params would be a sweet bonus :) > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Pieter Hugo
2012-Mar-09 10:48 UTC
Re: Re: Is there a way to redirect from one controller action to another without a server trip?
Thanks for the comments guys. If there is not wasy way to bounce to another controller/action then there should be. Its available via redirect_to, and one can render the partials of another controllers actions, but it seems one cant quite just get the action code to execute. My usage case is this: I am writing a web based simple text chat app. People submit comments, calling the AddComment action, which updates the conversation, and renders the comment to the people having the conversations. I want to build in some predefined keywords that will get recognised in the AddComment action, but will call another controller. Eg I have a documents controller with a AttachDoc action which gets called normally when the user clicks on the right button. I now want to allow doc attachment from the commandline - So when someone types ''AttachDoc'' as a comment, controll should jump to the documentscontroller. Redirect_to will do the job, but with a unnecessary trip back to the user. Still reading? thanks! Any suggestion? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
pepe
2012-Mar-09 13:43 UTC
Re: Is there a way to redirect from one controller action to another without a server trip?
Without thinking too much about it, how about if you create another
class that both your controllers can use?
# This class processes your actions
class YourActionClass
def your_action(params)
# here you process your request
end
end
# This is the controller you want to process the "redirect".
class ControllerA < ApplicationController
def your_action
your_action_instance = YourActionClass.new
your_action_instance.your_action(your_parameters)
end
end
# This is the controller you want to recognize your special cases and
redirect them.
class ControllerB < ApplicationController
def action
if special_case
your_action_instance = YourActionClass.new
your_action_instance.your_action(your_parameters)
# maybe you can render something here?
else
# your regular stuff goes here.
end
end
end
On Mar 8, 6:47 am, Pieter Hugo
<li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>
wrote:> Hi
>
> I want one controller action to invoke another action in another
> controller, but I don''t want the overhead of a redirect_to
response
> which then generates another request to the correct action and
> controller. Any suggestions?
>
> Pieter
>
> --
> Posted viahttp://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.