Setting up Fleximage


I've been trying today to setup fleximage to handle photo uploads to a
RoR application by following the tutorial that is provided

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 = 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"

- Now, it just returns the error "undefined method `photos_path' for

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. :slight_smile:

Model (photo.rb)
class Photo < ActiveRecord::Base
  acts_as_fleximage :image_directory => 'public/images/uploaded_photos'

Controller (photos_controller.rb)
class PhotosController < ApplicationController

def new


def create
  @photo =[:photo])
    redirect_to photo_url(@photo)
    flash[:notice] = 'Your photo did not pass validation!'
    render :action => 'new'


View (new.html.erb)
<% form_for @photo, :html => { :multipart => true } do |f| %>
    <b>Name</b><br />
    <%= f.text_field :name %>

    <b>Author</b><br />
    <%= f.text_field :author %>

    <b>Upload Image</b><br />
    <%= f.file_field :image_file %><br />
    or URL: <%= f.text_field :image_file_url %>

    <%= f.submit "Create" %>
<% end %>


I am sorry to hear your difficulties with the tutorial. I am a beginner in this group so I this you need to pose your question to someone who really knows what about ROR.

Good luck!


In your view (new.html.erb) file

This line <% form_for @photo, :html => { :multipart => true } do |f|
%> should be like below

<% form_for @photo, :url=>{:action=>'ACTIONNAME', }, :html =>
{ :multipart => true } do |f| %>

i.e give more argument :url=>{} to form_for

To overcome "undefined method `photos_path' for #<ActionView::Base: