Wednesday, February 29, 2012

Re: [Rails] Re: Re: Re: If photo field blank then?

On Feb 29, 2012, at 10:45 AM, Christopher Jones wrote:

> Walter Davis wrote in post #1049480:
>> On Feb 29, 2012, at 10:31 AM, Christopher Jones wrote:
>>
>>>>
>>> Hey Walter, good shout.
>>>
>>> I don't know where it is getting that line from.
>>
>> Aha! That is coming from deep in the heart of Paperclip. You have two
>> options. First, put your missing icon image at that path in your
>> application. Second, choose a different method to test on your model.
>> Instead of using the image accessor, look for one of the actual database
>> columns in your model. (Look in db/schema.rb at your column names, pick
>> something like photo_file_name or the local equivalent.) Then make the
>> test in the method something to match:
>>
>> (user.photo_file_name?) ? photo.url : 'default.png'
>>
>> The problem, as I should have picked up on from your earlier mention of
>> the missing photo never appearing, is that photo.url always returns
>> *something*, so it's not a good test subject for the ternary operator.
>>
>> Walter
>
> Fixed it,
>
> I simply added default_url : guest.png to my has_attached_file :photo
> model method.

Good one. Then you can also remove the whole custom accessor method, because any request of photo.url will always return something useful now. Just go back to where you started, with image_tag user.photo.url.

Walter


--
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@googlegroups.com.
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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate