What I wish to do is to have a construct like this in a view: <%= link_to_if <some test>, "New Model View", new_model_path -%> <some test> has to return true if new_model_path is defined and false otherwise. What is the proper idiom to do this in rails 2? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
James Byrne wrote: defined? new_model_path I do not know why I can spend so much time on something only to find the answer after I have asked for help. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi -- On Mon, 24 Mar 2008, James Byrne wrote:> > What I wish to do is to have a construct like this in a view: > > <%= link_to_if <some test>, "New Model View", new_model_path -%> > > <some test> has to return true if new_model_path is defined and false > otherwise. What is the proper idiom to do this in rails 2?I guess you could do: <% if respond_to?(:new_model_path) %> <%= link_to ... %> <% end %> but that seems very brittle to me. By the time you''re writing a view, you should know what helper methods and named routes exist, and which ones don''t. David -- Upcoming Rails training from David A. Black and Ruby Power and Light: ADVANCING WITH RAILS April 14-17 New York City INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin CORE RAILS June 24-27 London (Skills Matter) See http://www.rubypal.com for more info! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
James Byrne wrote: But I could not get it to work with link_to_if. This does not work (syntax error) <%= link_to_if((defined?(new_vendor_path)), ''New Vendor'', new_vendor_path) -%> but this does <%= link_to(''New Vendor'', new_vendor_path) if (defined? (new_vendor_path)) -%> Why? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
David A. Black wrote:> Hi -- >> but that seems very brittle to me. By the time you''re writing a view, > you should know what helper methods and named routes exist, and which > ones don''t. >Yes and I do/will. But for the moment I am writing one side of a bilaterally symmetrical application tree. I therefor wish to make this functionality dynamic since I am frequently adding and deleting that specific branch. It is not intended for production code. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mon, Mar 24, 2008 at 1:09 PM, James Byrne <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > James Byrne wrote: > > But I could not get it to work with link_to_if. > > This does not work (syntax error) > > <%= link_to_if((defined?(new_vendor_path)), ''New Vendor'', > new_vendor_path) -%>I wonder if you would have to write that as: <%= link_to_if(defined?(:new_vendor_path), ... (notice the ":")? newbies $.02 --wpd --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi -- On Mon, 24 Mar 2008, James Byrne wrote:> > David A. Black wrote: >> Hi -- >> > >> but that seems very brittle to me. By the time you''re writing a view, >> you should know what helper methods and named routes exist, and which >> ones don''t. >> > > Yes and I do/will. But for the moment I am writing one side of a > bilaterally symmetrical application tree. I therefor wish to make this > functionality dynamic since I am frequently adding and deleting that > specific branch. It is not intended for production code.I also converted your example to a plain if (instead of link_to_if) -- just an artifact of having been playing around with it, but I imagine you could translate it back :-) But my main point was about knowing the helpers, etc., and I understand your point about just trying it out. David -- Upcoming Rails training from David A. Black and Ruby Power and Light: ADVANCING WITH RAILS April 14-17 New York City INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin CORE RAILS June 24-27 London (Skills Matter) See http://www.rubypal.com for more info! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Patrick Doyle wrote:> > I wonder if you would have to write that as: > > <%= link_to_if(defined?(:new_vendor_path), ... > > (notice the ":")?I tried your suggestion and it does not change anything. I seemingly cannot get link_to_if to work in this instance. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 24, 2008, at 1:46 PM, James Byrne wrote:> Patrick Doyle wrote: >> I wonder if you would have to write that as: >> >> <%= link_to_if(defined?(:new_vendor_path), ... >> >> (notice the ":")? > > I tried your suggestion and it does not change anything. I seemingly > cannot get link_to_if to work in this instance.In order to call the link_to_if method, its arguments must first be evaluated. With David''s change to link_to(...) if defined? new_vendor_path the arguments to the link_to() are only evaluated after the "defined? new_vendor_path" has returned true. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---