Ok, I follow having all models respond to "title", but why would implementing the model's "to_s" method be a better approach? Is it just for consistency, always expecting to_s to return what the partial should display? How is that any different that expecting all models to answer to title?
Thanks. This has been really helpful. I used your example to create the following. Thoughts? http://pastie.org/402843 On Feb 27, 11:07 pm, Maurício Linhares <[email protected]> wrote: > On Fri, Feb 27, 2009 at 11:50 PM, ericindc <[email protected]> wrote: > > > And what about cases where I need the model attribute names to be > > different? For instance, in one case I might print item.name, but in > > the other, item.title. > > Make all models that are going to be used by that template respond to > the same message. If at your template, you're calling "item.title", > all models that are going to be used in there should have a "title" > method. In your case, you can just alias the "name" method to "title". > A better approach would be to implement the "to_s" method in your > active record models by returning these "name" properties. > > If you have a user model, you could implement it's to_s like the following: > > class User < ActiveRecord::Base > > def to_s > login > end > > end > > So you don't even care about what that model is, you just expect it's > to_s method to yield a correct "label". > > > And since this markup will be similar to the > > front-end display (non-admin), is there a good way to set the link_to > > to be either :admin or :root? > > You can just add another parameter at the render :partial call. > > - > Maurício Linhareshttp://alinhavado.wordpress.com/(pt-br) > |http://blog.codevader.com/(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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

