Difficult view code logic

this one really has me stumped…

<%= user.in_out == “In” ? {image_tag url_for_file_column(“personnel”,
“image”, “thumb”)} if user.image : user.in_out %>

What I am wanting to do…

if user.in_out == “In”, load their thumbnail if it exists, load
public/images/in.jpg if not, or else load public/images/out.jpg

Can someone help with the construction of this?

Craig

Perhaps just write a utility method in the user model, or in a helper
for this.

For instance, you could add these methods to your user class (untested):

def get_thumbnail
if in?
self.image.nil? ? ‘in.jpg’ : self.image
else
‘out.jpg’
end
end

def in?
self.in_out == ‘In’
end

Then in your view you could just say:

<%= image_tag(user.get_thumbnail()) %>

Tom

On 7/2/06, Craig W. [email protected] wrote:

Can someone help with the construction of this?

Craig


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Tom D.

http://atomgiant.com
http://gifthat.com

Hi Craig,

Craig W. wrote:

What I am wanting to do…

if user.in_out == “In”, load their thumbnail if it exists, load
public/images/in.jpg if not, or else load public/images/out.jpg

I’ve not used image_tag yet so I’ll not guess about the syntax for that,
but
WRT the other part…

<% if @user.in_out == ‘In’ %>
load public/images/in.jpg
<% else %>
load public/images/out.jpg
<% end %>

Notice that you’ll need to make the ‘user’ variable an instance variable
for
the view to have access to it.

hth,
Bill

On Sun, 2006-07-02 at 11:15 -0500, Bill W. wrote:

WRT the other part…

<% if @user.in_out == ‘In’ %>
load public/images/in.jpg
<% else %>
load public/images/out.jpg
<% end %>

Notice that you’ll need to make the ‘user’ variable an instance variable for
the view to have access to it.


thanks - the logic methology inside the view code was what I needed to
understand. I got it now

Thanks Tom too.

Craig