0

so I am working on a website that is a static scrollable one page, but for some reason it was deployed in ruby on rails. I am a noob in ror. There is one image in the html page that needs to resize whenever the site is loaded on a mobile device.

   <li><%= image_tag 'Main_logo.png', width: '700', height: '399' %></li>

Now I think I can do this in CSS, which means the client will resize and the full size image will always be downloaded. My question is how can I solve this issue using ror? I am sure ruby on rails has some server side capacity to fix this. Keep in mind I am new to ruby on rails

Thanks.

Huang
  • 1,355
  • 2
  • 11
  • 28

1 Answers1

1

To your problem of resizing images, you can use the gem rmagick (https://github.com/rmagick/rmagick)

The key line you probably need is thumb = img.resize_to_fit(75, 75), and the document explaining it well is at http://www.imagemagick.org/RMagick/doc/comtasks.html

To your problem of detecting mobile browsers: SO post Detecting mobile browsers in Rails 3

Or if you want a super quick and dirty way, you can paste this into your controller: http://detectmobilebrowsers.com/

Community
  • 1
  • 1
ForgetfulFellow
  • 2,477
  • 2
  • 22
  • 33
  • Leave a comment if you need some specific help! – ForgetfulFellow Jul 26 '14 at 19:37
  • thanks for this, I am kinda new to ROR, all my app has is a single webpage called home.html.erb under app-views-pages, and some css files under app-assets-stylesheets. Now I have an image tag in my original question to identify the image, how do IO use that with rmagick? do I need to do that in the controller? Model? – Huang Jul 26 '14 at 19:45
  • 1
    See if Ryan Bate's Screencast will help you understand Rmagick better; he can do a whole lot more explaining than I can :) http://railscasts.com/episodes/374-image-manipulation – ForgetfulFellow Jul 26 '14 at 21:29