Hello!
I’ve been trying today to setup fleximage to handle photo uploads to a
RoR application by following the tutorial that is provided
(GitHub: Let’s build from here · GitHub)
Originally, I just dropped in all of the sample code that they provided,
which I copied below this question.
-
When I tried to access “new” to upload a new photo, I received an
error of “Called id for nil, which would mistakenly be 4 – if you
really wanted the id of nil, use object_id”, which I understood to be
caused by the fact that I was using @photo without initializing it in
the controller. -
I added @photo = Photo.new to the controller for “new” but then it
returned that it could not find the table Photo. -
I created a new migration for a photo table, including only the fields
for name and author, which are also requested in the provided “new”
view. -
Now, it just returns the error “undefined method `photos_path’ for
#ActionView::Base:0x230ee70”
Since I’m incredibly new to fleximage, I’m not exactly sure if I’m going
in the wrong direction with my troubleshooting, if a table even needed
to be created for the photos or what my next step should be.
If anyone could point me in the right direction, I’d appreciate it.
Model (photo.rb)
class Photo < ActiveRecord::Base
acts_as_fleximage :image_directory => ‘public/images/uploaded_photos’
end
Controller (photos_controller.rb)
class PhotosController < ApplicationController
def new
end
def create
@photo = Photo.new(params[:photo])
if @photo.save
redirect_to photo_url(@photo)
else
flash[:notice] = ‘Your photo did not pass validation!’
render :action => ‘new’
end
end
end
View (new.html.erb)
<% form_for @photo, :html => { :multipart => true } do |f| %>
Name
<%= f.text_field :name %>
Author
<%= f.text_field :author %>
Upload Image
<%= f.file_field :image_file %>
or URL: <%= f.text_field :image_file_url %>
<%= f.submit "Create" %>
<% end %>