This code, in my view(.rhtml file) causes the error
which I’ll post below.
-----The Code-----
<%= if (@announcement.image == nil) then
Download
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\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
<% if condition %>
<% else %>
<% end %>
Inside each part use normal ERB tags and HTML.
No luck!
The problem seems to be with the <a href part of the
code.
— Robert W. [email protected] wrote:
<%= if (@announcement.image == nil) then
Download
end %>
----The Error----
compile error
./script/…/config/…/app/views/committee/audit_archive.rhtml:118:
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
<%= if (@announcement.image == nil) then
<% if @announcement.image.nil? %>
…
<% end %>
Ruby ain’t PHP 
Both work, but for the sake of RUBY I probably should
write it like this. Thanks.
— Sven S. [email protected]
wrote:
____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search.
http://tools.search.yahoo.com/newsearch/category.php?category=shopping
Hi –
On Thu, 17 Jan 2008, jonathan Mcintire wrote:
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!
This did it!
Thanks for responding everyone.
— Jeremy Weiskotten
[email protected] wrote:
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now.
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
Try this…
<% if @announcement.image.nil? %>
<%= link_to ‘Download’, url_for_file_column(‘announcement’, ‘image’) %>
<% end %>