Sunday, December 16, 2012

[Rails] Re: Running code in another controller action

On Dec 16, 9:24 am, rubyrookie <asajn...@gmail.com> 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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate