Alexey
2012-Oct-04 10:11 UTC
How to make a model or a model decorator aware of its controller in Rails?
Is a decorator, like Draper, a good place to store the controller and routes associated with a given model? I would like to be able to pass one or several model objects to a generic view, and have the view automatically generate links to the actions associated with the objects. Like this: link_to object.public_send(attribute), { :controller => object.controller_path, :action => :show, :id => object.id } Thank you for any suggestions of what would be a common practice. I have also posted this question on SO: http://stackoverflow.com/questions/12713784. -- 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/-/boHiwI4JxsIJ. For more options, visit https://groups.google.com/groups/opt_out.
Alexey
2012-Oct-08 08:38 UTC
Re: How to make a model or a model decorator aware of its controller in Rails?
I will answer myself: i think a decorator is not a good place to store an associated controller, a decorator should only know about model data and HTML markup. I am still looking for a good solution. -- 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/-/hgbZ5WKDrtgJ. For more options, visit https://groups.google.com/groups/opt_out.
Brett McHargue
2012-Oct-08 09:02 UTC
Re: Re: How to make a model or a model decorator aware of its controller in Rails?
You could check out http://objectsonrails.com/ and https://github.com/objects-on-rails/display-case - as it says, it brings together the model and context (which could be a controller) brett On Mon, Oct 8, 2012 at 9:38 AM, Alexey <alexey.muranov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I will answer myself: i think a decorator is not a good place to store an > associated controller, a decorator should only know about model data and > HTML markup. I am still looking for a good solution. > > -- > 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/-/hgbZ5WKDrtgJ. > > 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.
Matt Jones
2012-Oct-08 17:37 UTC
Re: How to make a model or a model decorator aware of its controller in Rails?
On Monday, 8 October 2012 01:38:22 UTC-7, Alexey wrote:> > I will answer myself: i think a decorator is not a good place to store an > associated controller, a decorator should only know about model data and > HTML markup. I am still looking for a good solution.In your example, the controller path seems *highly* relevant to generating HTML markup... --Matt Jones -- 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/-/BEfhyQe09M0J. For more options, visit https://groups.google.com/groups/opt_out.
Alexey
2012-Oct-12 07:24 UTC
Re: How to make a model or a model decorator aware of its controller in Rails?
On Monday, October 8, 2012 7:37:21 PM UTC+2, Matt Jones wrote:> > > > On Monday, 8 October 2012 01:38:22 UTC-7, Alexey wrote: >> >> I will answer myself: i think a decorator is not a good place to store an >> associated controller, a decorator should only know about model data and >> HTML markup. I am still looking for a good solution. > > > In your example, the controller path seems *highly* relevant to generating > HTML markup... > > --Matt Jones > >Matt, i do not agree: if my application changes the host, or i decide to change route names or controller names, the link urls will change, but html tags or model behavior will not. I think controller awareness should be added on a different level, not in a decorator (single responsibility principle). -Alexey. -- 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/-/bstYup5LzikJ. For more options, visit https://groups.google.com/groups/opt_out.
Alexey
2012-Oct-12 07:26 UTC
Re: Re: How to make a model or a model decorator aware of its controller in Rails?
On Monday, October 8, 2012 11:02:19 AM UTC+2, Brett McHargue wrote:> > You could check out http://objectsonrails.com/ and > https://github.com/objects-on-rails/display-case - as it says, it > brings together the model and context (which could be a controller) > > brett > > Thanks, i''ll look into it.-Alexey. -- 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/-/Gv8aFj1IGEkJ. For more options, visit https://groups.google.com/groups/opt_out.
Alexey
2012-Oct-13 20:49 UTC
Re: Re: How to make a model or a model decorator aware of its controller in Rails?
On Monday, October 8, 2012 11:02:19 AM UTC+2, Brett McHargue wrote:> > You could check out http://objectsonrails.com/ and > https://github.com/objects-on-rails/display-case - as it says, it > brings together the model and context (which could be a controller) > > brettI do not know if i will be able to apply it to my problem, but this tutorial is very interesting and helpful, thanks. - A. -- 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/-/V6uHG8yYtY8J. For more options, visit https://groups.google.com/groups/opt_out.