Ruby on Rails Wednesday, May 18, 2016

> On May 18, 2016, at 1:48 PM, W. M. <lists@ruby-forum.com> wrote:
>
> Walter Davis wrote in post #1183529:
>> You would define those in your view, just as for any other image type.
>> http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/image_tag
>>
>> Walter
>
> I need to specify different alt/title attributes for the different
> uploaded images. I guess I have to create an image model that specifies
> an image + title or alt attribute as a string and then nest this model
> inside another one (e.g. posts or articles etc..). I am still one week
> into rails, but I believe this is the rails way to do it.
>

The usual way that you do that is to define columns on the ActiveRecord model that has the image attached to it, and then when you use the image_tag helper, you can access those and use them.

image_tag @your_object.file.thumb('200x200#').url, alt: @your_object.alt, title: @your_object.title

If you haven't done so already, please do yourself a favor and invest a few days in working all the way through railstutorial.org. It's free to read and use on line, and it is the best way to learn the basics (and more importantly, the idioms) of Rails. It is an investment that will pay off for years to come.

Walter

> --
> 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/031108fdbac5b35e3c157f44080dea18%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1635FAE5-C136-40B7-98A3-31245DA3CDBF%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment