In my application, I''m doing this a lot in the view code: <% if admin? %> <%= link_to "Show", :action => ''show'', :id => @item.id %> | <%= link_to "Edit", :action => ''edit'', :id => @item.id %> | <%= link_to "Delete", :action => ''delete'', :id => @item.id %> <% end %> Although, sometimes there''s no delete or show link. What''s a good way to generalize that? Partial? And pass in an options hash to determine if the show and delete options should be displayed?
maybe something like this: <%= admin_links @item, :show, :edit, :delete %> something like this : (untested) def admin_links(item, *calls) return '''' unless admin? calls.collect do |call| link_to call.humanzie, :action => call.to_s, :id => item end.join(" ") end On 8/28/05, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In my application, I''m doing this a lot in the view code: > > <% if admin? %> > <%= link_to "Show", :action => ''show'', :id => @item.id %> | > <%= link_to "Edit", :action => ''edit'', :id => @item.id %> | > <%= link_to "Delete", :action => ''delete'', :id => @item.id %> > <% end %> > > Although, sometimes there''s no delete or show link. > > What''s a good way to generalize that? Partial? And pass in an > options hash to determine if the show and delete options should be > displayed? > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Tobi http://typo.leetsoft.com - Open source weblog engine http://blog.leetsoft.com - Technical weblog
It looks like a good candidate for an application helper that takes two parameters, an id and a list of actions to link, and returns an array of link_to calls joined with '' | ''. On Aug 28, 2005, at 2:03 AM, Joe Van Dyk wrote:> In my application, I''m doing this a lot in the view code: > > <% if admin? %> > <%= link_to "Show", :action => ''show'', :id => @item.id %> | > <%= link_to "Edit", :action => ''edit'', :id => @item.id %> | > <%= link_to "Delete", :action => ''delete'', :id => @item.id %> > <% end %> > > Although, sometimes there''s no delete or show link. > > What''s a good way to generalize that? Partial? And pass in an > options hash to determine if the show and delete options should be > displayed? > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
both this and your ''mail_to'' question can benefit directly by adding helper methods instead of partials... wrapping the actual rails api: *cond_link_to*, *cond_mail_to* that takes an extra true/false/nil argument.. stick it directly into application_helper.rb if its used widely On 8/28/05, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > In my application, I''m doing this a lot in the view code: > > <% if admin? %> > <%= link_to "Show", :action => ''show'', :id => @item.id <http://item.id> %> > | > <%= link_to "Edit", :action => ''edit'', :id => @item.id <http://item.id> %> > | > <%= link_to "Delete", :action => ''delete'', :id => @item.id<http://item.id>%> > <% end %> > > Although, sometimes there''s no delete or show link. > > What''s a good way to generalize that? Partial? And pass in an > options hash to determine if the show and delete options should be > displayed? > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
If I understand you correctly, your problem isn''t writing those lines themselves. The problem is that you are doing that *a lot*, right? What I did was to add that code in the layout file. And then your next question is "Well, that''s what I am doing, but there are multiple controllers, which means multiple layout-files". I had the same problems with this, and in *my* case (might not work for you). I ended up adding this code in the application.rhtml file, and specifying layout ''application'' for all my controllers. I found that to be helpful at least, since I didn''t want to change the general look of the page based on which controller was doing the job. Good luck. ------------------------------------------------------------------------ /*Ronny Hanssen*/ Joe Van Dyk wrote:> In my application, I''m doing this a lot in the view code: > > <% if admin? %> > <%= link_to "Show", :action => ''show'', :id => @item.id %> | > <%= link_to "Edit", :action => ''edit'', :id => @item.id %> | > <%= link_to "Delete", :action => ''delete'', :id => @item.id %> > <% end %> > > Although, sometimes there''s no delete or show link. > > What''s a good way to generalize that? Partial? And pass in an > options hash to determine if the show and delete options should be > displayed? > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >