I am doing a partial render in the view from one controller. Here is the code -> <%= render :template => ''restaurants/new'' %>. I want the other controller new action code to do it. Is there a way to call an action in another controller ? I don''t want to duplicate the same code in two controllers. -- 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/H1BxDgwDjr4J. For more options, visit https://groups.google.com/groups/opt_out.
On Dec 16, 9:24 am, rubyrookie <asajn...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am doing a partial render in the view from one controller. Here is the > code -> <%= render :template => ''restaurants/new'' %>. I want the other > controller new action code to do it. Is there a way to call an action in > another controller ? I don''t want to duplicate the same code in two > controllers.In a nutshell, no. If you need to do this you might want to look at: - putting the shared code into a module - putting it into a common ancestor of the 2 classes - moving the functionality into a helper that both controllers can share - look at cells gem, which is one way of having reusable units of view + code Fred -- 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 https://groups.google.com/groups/opt_out.
Thanks . I am experiment by putting common code in a helper . How Do i
access it from my controller. I tried to do
ApplicationHelper::base64_url_decode in the ApplicationController bu I am
getting method not defined. Any ideas? :)
module ApplicationHelper
def base64_url_decode str
encoded_str =
str.gsub(''-'',''+'').gsub(''_'',''/'')
encoded_str += ''='' while !(encoded_str.size % 4).zero?
Base64.decode64(encoded_str)
end
def decode_data str
encoded_sig, payload = str.split(''.'')
data = ActiveSupport::JSON.decode base64_url_decode(payload)
end
end
On Sunday, December 16, 2012 2:20:45 AM UTC-8, Frederick Cheung
wrote:>
>
>
> On Dec 16, 9:24 am, rubyrookie
<asajn...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > I am doing a partial render in the view from one controller. Here is
the
> > code -> <%= render :template =>
''restaurants/new'' %>. I want the
> other
> > controller new action code to do it. Is there a way to call an action
> in
> > another controller ? I don''t want to duplicate the same code
in two
> > controllers.
>
> In a nutshell, no. If you need to do this you might want to look at:
>
> - putting the shared code into a module
> - putting it into a common ancestor of the 2 classes
> - moving the functionality into a helper that both controllers can
> share
> - look at cells gem, which is one way of having reusable units of view
> + code
>
> Fred
>
--
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
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/_9lmzrjMNsMJ.
For more options, visit https://groups.google.com/groups/opt_out.
Put it in application_controller.rb On 12/16/2012 08:38 PM, rubyrookie wrote:> > Thanks . I am experiment by putting common code in a helper . How Do i > access it from my controller. I tried to do > ApplicationHelper::base64_url_decode in the ApplicationController bu I > am getting method not defined. Any ideas? :) > > module ApplicationHelper > > def base64_url_decode str > encoded_str = str.gsub(''-'',''+'').gsub(''_'',''/'') > encoded_str += ''='' while !(encoded_str.size % 4).zero? > Base64.decode64(encoded_str) > end > > def decode_data str > encoded_sig, payload = str.split(''.'') > data = ActiveSupport::JSON.decode base64_url_decode(payload) > end > end > > > On Sunday, December 16, 2012 2:20:45 AM UTC-8, Frederick Cheung wrote: > > > > On Dec 16, 9:24 am, rubyrookie <asajn...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I am doing a partial render in the view from one controller. > Here is the > > code -> <%= render :template => ''restaurants/new'' %>. I want > the other > > controller new action code to do it. Is there a way to call an > action in > > another controller ? I don''t want to duplicate the same code in two > > controllers. > > In a nutshell, no. If you need to do this you might want to look at: > > - putting the shared code into a module > - putting it into a common ancestor of the 2 classes > - moving the functionality into a helper that both controllers can > share > - look at cells gem, which is one way of having reusable units of > view > + code > > Fred > > -- > 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 > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/_9lmzrjMNsMJ. > For more options, visit https://groups.google.com/groups/opt_out. > >-- 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 https://groups.google.com/groups/opt_out.