Reputation:
Hello and sorry for such a basic question, but I have exhausted all search options.
My question is how do I find an image path? I am starting to learn Ruby on Rails and a gem I am trying to integrate requires me to specify an image path:
colors = Miro::DominantColors.new('/path/to/local/image.jpg')
How do I find the path to a local image saved to my desktop?
I am trying to use the Miro RoR gem (https://github.com/jonbuda/miro).
Thank yo, Brian
Upvotes: 1
Views: 153
Reputation:
Thanks for the advice and links to paperclip tutorials, Rich. I'll definitely be using those resources in the near future.
The solution was too simple, and I feel guilty for asking the question haha. All I had to do was use terminal to navigate to the image then just $pwd to get the path.
Upvotes: 0
Reputation: 76784
You're going to have to upload the image
Images
The problem you've got is Rails is server-side
You're trying to load an image from your client-side system (your desktop)
This means that in order to get Rails to process the image in any way, you will have to first upload the image into the system, then process it. The recommended way to do this is to use the Paperclip gem (for image uploads), then you can use your Miro gem to process the image
Here's what I'd do:
Upload
You'll first have to upload the image
There are numerous ways to do this, but the process is the same:
image
model & db (to store the image)upload
formupload
through controller
Model
#app/models/image.rb
Class Image < ActiveRecord::Base
has_attached_file :image
end
Controller
#app/controllers/images_controller.rb
def new
@image = Image.new
end
def create
@image = Image.new(image_params)
@image.save
end
private
def image_params
params.require(:image).permit(:image)
end
View
#app/views/images/new.html.erb
<%= form_for @image do |f| %>
<%= f.file_field :image %>
<% end %>
Process
After saving the image, you can then call one of Paperclip's processing methods to manage the uploaded image's processing. Here are some ideas on how you may do this:
Upvotes: 1