Ruby on Rails - Unable to add "".jpg" file - ruby-on-rails

I am new to the Ruby on Rails.
I want to add ".jpg" file under the /Public/Images folder.
When I navigate to the add New page, I don't see the Picture Format in the menu.

If you are working with rails3.1 or next of that, there is an app/assets/images folder in your application directory. And there is a default image rails.png available.
Add any images over there and use them as follows:
<%= image_tag "/assets/rails.png"%>

Related

How do I browse folder using simple_form?

I want to add a file/folder browsing button in my rails application using simple_form gem.
How do I do it? In simple_form documentation it is not mentioned.
Edit: File browse is mentioned in the documentation. But how to browse folders is not mentioned. Currently the only way I think possible is extract the folder from the file path. But what if there are no files present in the folder?
You would do:
f.input :somename, as: :file

Routing Error - Switching Index File in Rails - Bootstrap Theme Implementation

I am trying to implement a bootstrap theme in my rails app I just created.
First I created new project with Rails new scaffold, and created a database. the Index page worked fine, showing a table of the database content. (I am using this tutorial to go through it:https://launchschool.com/blog/integrating-rails-and-bootstrap-part-1)
However, as I try to implement the bootstrap theme, I am running into an issue. I read from another tutorial to manually copy and paste the contents of the bootstrap theme over to my apps corresponding folders. My goal is to copy the bootstrap's template index.html file over, so that I can start from there.
I am trying to replace the default index.html.erb file with the index.html file that came with my bootstrap theme. So I copy the file, rename it to match the original file. Then remove the original index html file. But when I do this my routing won't work. I get the routing error listed below.
What do I do? If I put the old index file pack in the views it works again. But when I try to switch it stops working.
I get this error when trying to load the page:
Routing Error
No route matches [GET] "/index"
Rails.root: /Users/../code/lettersTest3

Rails 4.2 not loading correct image

I'm working on the depot_a app from Agile Web Development with Rails 4. Following the steps in Task A, all images are in app/assets/images/:
[~/projects/try_ruby/depot]$ ls app/assets/images/
cs.jpg logo.png rails.png rtp.jpg ruby.jpg
In app/views/products/index.html.erb, the code to present the image:
<%= image_tag(product.image_url, class: 'list_image') %>
Instead of accessing asset/cs.jpg, it actually generates the obfusticated image path (see the screenshot): /assets/cs-436e7e2d621d24ea1d19769362306ecdec83fcd62d5d45f135adca63e6a0f9c5.jpg.
Why is that?
The jpg contains error:
EDIT:
My rails version is 4.2. But the book's depot app is based on Rails 4.0. So I downgraded Rails to 4.0 and re-did the steps again (regenerated scaffold, db seeding, etc.), then the jpg photos are shown correctly. It seems like a version thing. But I still don't know why jpg doesn't load in Rails 4.2.
The obfusticated image path /assets/cs-436e7e2d621d24ea1d19769362306ecdec83fcd62d5d45f135adca63e6a0f9c5.jpg. could be from the public/assets directory and not app/assets directory. The possible reason is that you precompiled your assets.

Download image from database to project folder with Paperclip

I want to download an image stored in database with paperclip and put it in my project folder. In app/assets/images for example.
Why? : Because I want to put image in a Word. So when I use docx_replace or caracal gem I cant put directly image within the variable from database (that don't work). But I can put image directly from folder. So I want to put the image from DB to folder, put in the Word and delete it after insertion. That's why. But if you have another technique tell me.
Do you now a way in order to do that ?
As you store your files locally and paperclip provides helpers to the full path of the file, you can just use Ruby FileUtils to copy the file to the public directory in your action. You don't need to download it, because it is already in the filesystem.
This answer provides some base code for this: https://stackoverflow.com/a/5776577/1023609

In Refinery CMS, how do I replace the favicon?

I have replaced the file located at public/favicon.ico with my icon file. But when I load the page, I still see the default Refinery warped bumblebee icon.
I have done the various refresh tricks to ensure I'm not looking at a cache.
Looking at the source, the icon url is /assets/favicon.ico. When I load that url directly, I still see the old favicon.
I have also searched my project directory for other favicon files, but mine is the only one.
Finally got it. I copied my favicon file into the app/assets/images folder.
Then I used this tag in my head partial:
<%= favicon_link_tag image_path('favicon.ico?v=2') %>

Resources