Topic: attachment_fu problem

Hi all,

I been following this tutorial,
http://clarkware.com/cgi/blosxom/2007/0 … leUploadFu
and since I'm not very good with Rails yet I got this error when tried to run the application.

undefined local variable or method `mugshots_path' for #<#<Class:0xb6abfe58>:0xb6abfe30>

but I don't understand very well where the problem is or what the error means, did I miss something?

here is my code http://pastie.caboo.se/73714

thanks in advance

Last edited by diego (2007-06-26 14:07:43)

Re: attachment_fu problem

the controller should be called mugshots and you should have the resource in the routes.rb file.

map.resources :mugshots

--

Re: attachment_fu problem

The errors probably being thrown by the line:

<% form_for(:mugshot, :url => mugshots_path, 
                      :html => { :multipart => true }) do |f| -%>

I believe you need to set up restful routes for the line to work. In your config/routes.rb try adding:
map.resources :mugshots

Or in place of :url => mugshots_path put :url => { :controller => "mugshots", :action => "index" }.

Edit: Oops, BasicMind beat me to it wink

Alex

Last edited by alexpt (2007-06-26 14:22:03)

Re: attachment_fu problem

why is the routes needed?

Last edited by diego (2007-06-26 16:35:21)

Re: attachment_fu problem

Its just because the author uses named routes (things like mugshots_path, edit_mugshots_path) which are just a nicety of using RESTful routes.

:url => { :controller => "mugshots", :action => "index" } will do exactly the same thing as :url => mugshots_path, its just a little longer.

Alex

Re: attachment_fu problem

alexpt wrote:

Its just because the author uses named routes (things like mugshots_path, edit_mugshots_path) which are just a nicety of using RESTful routes.

:url => { :controller => "mugshots", :action => "index" } will do exactly the same thing as :url => mugshots_path, its just a little longer.

Alex

i've tried to skip the map.resources :mugshots in the config/routes.rb file, with the map.resources :mugshots works fine, but i did what you said, i just put :url => { :controller => 'mugshots', :action => 'index' } and skipped the routes but didnt work, the images didn't go to the public/images... is there a way to make it work without the routes and use :url => { :controller => 'mugshots', :action => 'index' } or something else instead?

Re: attachment_fu problem

is possible to integrate attachment_fu to any controller, or is locked to the mugshots name? can i use it with a scaffold?

and if is possible, how?

thanks in advance

Last edited by diego (2007-06-26 22:42:14)

Re: attachment_fu problem

yes, I have it working with a controller/model called Photos,

your controller is called TestController, change it to mugshots, or change all links to TestController.

Last edited by BasicMind (2007-06-27 03:23:55)

--

Re: attachment_fu problem

change this in the form

<% form_for(:mugshot, :url => mugshots_path,
                      :html => { :multipart => true }) do |f| -%>
to
<% form_for(:mugshot, :url => {:action => 'create'},
                      :html => { :multipart => true }) do |f| -%>

and in the controller

redirect_to mugshot_url(@mugshot)
to
redirect_to :controller => 'test', :action => 'index'

--

10

Re: attachment_fu problem

I have followed the steps as you mentioned and am able to upload images. I just want to store a couple of extra things in my table such as title. My table has a column called title. I know I have to use the text_field tag but am not sure how to do this.

<--upload_controller.rb>
class UploadController < ApplicationController

    def index
        @logo = Logo.find(:all, :conditions => {:parent_id => nil})
    end

    def new
      @logo = Logo.new
    end

    def create
      @logo = Logo.new(params[:logo])
      if @logo.save
        flash[:notice] = 'Logo was successfully created.'
        redirect_to :controller => 'upload', :action => 'index'   
      else
        render :action => :new
      end
    end

end

<--new.rhtml-->
<%= error_messages_for :logo %>

<% form_for(:logo, :url => {:action => 'create'},
                      :html => { :multipart => true }) do |f| -%>
  <p>
    <label for="mugshot">Upload A Logo:</label>
    <%= f.file_field :uploaded_data %>
  <p>
    <%= submit_tag 'Create' %>
  </p>
<% end -%>

<--logo.rb-->
class Logo < ActiveRecord::Base

    has_attachment   :content_type => :image,
                     :storage => :file_system,
                     :max_size => 500.kilobytes,
                     :resize_to => '320x200>',
                     :thumbnails => { :thumb => '100x100>' }
             :comment

    validates_as_attachment

end