jonathan Mcintire
2008-Jan-17 20:03 UTC
Trying to put ruby code in an if then statement in .rhtml
This code, in my view(.rhtml file) causes the error which I''ll post below. -----The Code----- <%= if (@announcement.image == nil) then <a href = "<%= url_for_file_column(''announcement'', ''image'') %>" >Download</a> end %> ----The Error---- compile error ./script/../config/../app/views/committee/audit_archive.rhtml:118: syntax error <a href = "<%url_for_file_column(''announcement'', ''image'') ).to_s); _erbout.concat "\" >Download</a>\n" Any ideas on the cause of this? Thanks for any and all help! ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Robert Walker
2008-Jan-17 20:32 UTC
Re: Trying to put ruby code in an if then statement in .rhtml
Use <% if... Not <%= if... On Jan 17, 3:03 pm, jonathan Mcintire <hatejo...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> This code, in my view(.rhtml file) causes the error > which I''ll post below. > > -----The Code----- > <%= if (@announcement.image == nil) then > > <a href = "<%= url_for_file_column(''announcement'', > ''image'') %>" >Download</a> > > end %> > > ----The Error---- > compile error > ./script/../config/../app/views/committee/audit_archive.rhtml:118: > syntax error > <a href = "<%> url_for_file_column(''announcement'', ''image'') ).to_s); > _erbout.concat "\" >Download</a>\n" > > Any ideas on the cause of this? Thanks for any and > all help! > > ___________________________________________________________________________ _________ > Be a better friend, newshound, and > know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Robert Walker
2008-Jan-17 20:40 UTC
Re: Trying to put ruby code in an if then statement in .rhtml
<% if condition %> <% else %> <% end %> Inside each part use normal ERB tags and HTML. On Jan 17, 3:32 pm, Robert Walker <rwalker...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Use <% if... Not <%= if... > > On Jan 17, 3:03 pm, jonathan Mcintire <hatejo...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote: > > > This code, in my view(.rhtml file) causes the error > > which I''ll post below. > > > -----The Code----- > > <%= if (@announcement.image == nil) then > > > <a href = "<%= url_for_file_column(''announcement'', > > ''image'') %>" >Download</a> > > > end %> > > > ----The Error---- > > compile error > > ./script/../config/../app/views/committee/audit_archive.rhtml:118: > > syntax error > > <a href = "<%> > url_for_file_column(''announcement'', ''image'') ).to_s); > > _erbout.concat "\" >Download</a>\n" > > > Any ideas on the cause of this? Thanks for any and > > all help! > > > ___________________________________________________________________________ _________ > > Be a better friend, newshound, and > > know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
jonathan Mcintire
2008-Jan-17 20:43 UTC
Re: Trying to put ruby code in an if then statement in .rhtml
No luck! The problem seems to be with the <a href part of the code. --- Robert Walker <rwalker348-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Use <% if... Not <%= if... > > On Jan 17, 3:03 pm, jonathan Mcintire > <hatejo...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote: > > This code, in my view(.rhtml file) causes the > error > > which I''ll post below. > > > > -----The Code----- > > <%= if (@announcement.image == nil) then > > > > <a href = "<%= url_for_file_column(''announcement'', > > ''image'') %>" >Download</a> > > > > end %> > > > > ----The Error---- > > compile error > > >./script/../config/../app/views/committee/audit_archive.rhtml:118:> > syntax error > > <a href = "<%> > url_for_file_column(''announcement'', ''image'') > ).to_s); > > _erbout.concat "\" >Download</a>\n" > > > > Any ideas on the cause of this? Thanks for any > and > > all help! > > > > >___________________________________________________________________________> _________ > > Be a better friend, newshound, and > > know-it-all with Yahoo! Mobile. Try it now. >http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ> > >____________________________________________________________________________________ Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sven Schwyn
2008-Jan-17 20:44 UTC
Re: Trying to put ruby code in an if then statement in .rhtm
> <%= if (@announcement.image == nil) then<% if @announcement.image.nil? %> ... <% end %> Ruby ain''t PHP :-) -- 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 -~----------~----~----~----~------~----~------~--~---
jonathan Mcintire
2008-Jan-17 20:49 UTC
Re: Trying to put ruby code in an if then statement in .rhtm
Both work, but for the sake of RUBY I probably should write it like this. Thanks. --- Sven Schwyn <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > <%= if (@announcement.image == nil) then > > <% if @announcement.image.nil? %> > ... > <% end %> > > Ruby ain''t PHP :-) > -- > Posted via http://www.ruby-forum.com/. > > > >____________________________________________________________________________________ Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping --~--~---------~--~----~------------~-------~--~----~ 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
2008-Jan-17 20:54 UTC
Re: Trying to put ruby code in an if then statement in .rhtml
Hi -- On Thu, 17 Jan 2008, jonathan Mcintire wrote:> > This code, in my view(.rhtml file) causes the error > which I''ll post below. > > -----The Code----- > <%= if (@announcement.image == nil) then > > <a href = "<%= url_for_file_column(''announcement'', > ''image'') %>" >Download</a> > > end %>See other replies for the right technique. One comment I''ll make is to note in particular that ERb delimiters are not reentrant. To insert a string conditionally, you could do something like this: <%= "<a href=#{url_for_file_column(''announcement'',''image)}" if @announcement.image.nil %> and if the "if" fails, the whole expression will be nil, which will be interpolated as an empty string. It''s not generally the best way to do it, though; the separate <% if %> ... <% end %> things are better, because they''re easier to parse visually and also they don''t interpolate anything, not even an empty string. Also, the if-modifier is fragile; it won''t be happy if you break the line before it. I would mainly use the above technique for short things like: <%= @user.middle_name %> where I can go ahead and do the interpolation without really caring whether the value is nil or not (or "" for that matter). Except what I''d really do is write a User#whole_name method :-) But you see the point. David -- Training for 2008! Ruby on Rails training by David A. Black/Ruby Power and Light, LLC: * Intro to Rails, New York, NY, February 4-7 2008 * Advancing With Rails, New York, NY, February 11-14 2008 Hosted by Exceed Education. See http://www.rubypal.com for details! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jeremy Weiskotten
2008-Jan-17 20:54 UTC
Re: Trying to put ruby code in an if then statement in .rhtm
Try this... <% if @announcement.image.nil? %> <%= link_to ''Download'', url_for_file_column(''announcement'', ''image'') %> <% end %> -- 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 -~----------~----~----~----~------~----~------~--~---
jonathan Mcintire
2008-Jan-17 21:01 UTC
Re: Trying to put ruby code in an if then statement in .rhtm
This did it! Thanks for responding everyone. --- Jeremy Weiskotten <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Try this... > > > <% if @announcement.image.nil? %> > <%= link_to ''Download'', > url_for_file_column(''announcement'', ''image'') %> > <% end %> > -- > Posted via http://www.ruby-forum.com/. > > > >____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---