Attachment_Fu

10 views
Skip to first unread message

David Sedeño

unread,
Jan 23, 2008, 1:26:22 PM1/23/08
to ActiveScaffold : Ruby on Rails plugin
Hi,

I'm trying to use attachment_fu with AS without luck. I have one Image
model and a Person model that have a has_many :images.

I have the AS in a people_controller but in the create form show the
columns of the images table instead of a file dialog.

I known that AS is better with file_column but I need to add more than
one images to the Person model.

Thanks

David

Sergio Cambra

unread,
Jan 23, 2008, 5:05:35 PM1/23/08
to actives...@googlegroups.com

I'm using attachment_fu. Try with this:
config.columns.add :uploaded_data # create uploaded_data column
config.columns.exclude :uploaded_data # don't use uploaded_data,
except in create
config.create.multipart = true
config.create.columns = [:uploaded_data, :title]

And add to the helper
def uploaded_data_form_column(record, input_name)
file_field_tag input_name
end

I hope that's all, but I may forget something.

David Sedeño

unread,
Jan 24, 2008, 4:34:44 AM1/24/08
to actives...@googlegroups.com
Hi,

Thanks for your response.

With your approach, you can only upload one image at a time, isn't it?

Also, it would be great that you can edit the images (add more, remove them) in the edit Person form.

Cheers
---
David Sedeño

2008/1/23, Sergio Cambra <ser...@ensanjose.net>:

sergio

unread,
Jan 24, 2008, 9:19:51 AM1/24/08
to actives...@googlegroups.com
On Thu, 24 Jan 2008 10:34:44 +0100, "David Sedeño" <fri...@gmail.com>
wrote:

> Hi,
>
> Thanks for your response.
>
> With your approach, you can only upload one image at a time, isn't it?
>
> Also, it would be great that you can edit the images (add more, remove
> them)
> in the edit Person form.

One image on each Image model. But a person could have more than one image
objects (has_many :images). I'm using it like that.

David Sedeño

unread,
Jan 24, 2008, 2:50:55 PM1/24/08
to actives...@googlegroups.com
2008/1/24, sergio <ser...@ensanjose.net>:

One image on each Image model. But a person could have more than one image
objects (has_many :images). I'm using it like that.

Yes, I have the same:

class Person < ActiveRecord::Base
  has_many :images
end

class Image < ActiveRecord::Base
 ...attachment_fu_definitions...
 belongs_to :person
end

class PersonController < ApplicationController
  active_scaffold :person do |config|
    config.columns.add :uploaded_data
    config.create.multipart = true
    config.create.columns = [:uploaded_data, :name]
  end
end

And the helper as you say. But with this:
- There are a problem when saving the data: NoMethodError (undefined method `uploaded_data' for #<Person
- Also, as I say early, you can upload only _one_ image to the person object.

Thanks again

David

sergio

unread,
Jan 25, 2008, 4:41:52 AM1/25/08
to actives...@googlegroups.com
> Yes, I have the same:
>
> class Person < ActiveRecord::Base
> has_many :images
> end
>
> class Image < ActiveRecord::Base
> ...attachment_fu_definitions...
> belongs_to :person
> end
>
> class PersonController < ApplicationController
> active_scaffold :person do |config|
> config.columns.add :uploaded_data
> config.create.multipart = true
> config.create.columns = [:uploaded_data, :name]
> end
> end
>
> And the helper as you say. But with this:
> - There are a problem when saving the data: NoMethodError (undefined
> method
> `uploaded_data' for #<Person

You need define in Person the uploaded_data method:
def uploaded_data
nil
end

It's used to show the value in uploaded_data field. You will need to define
another method to create the image.
def uploaded_data=(data)
self.images << Image.new(:uploaded_data => data)
end

> - Also, as I say early, you can upload only _one_ image to the person
> object.

I use an action link to open a nested list with the images, and then use
the nested create new to upload a new image. You can try to use a
ImageController with uploaded_data in create form and use subform to show
create form for imagen in person create and update form. Although I tried
this at first with create form and it doesn't working (because person
didn't exist yet).

Also you can use create like you are doing now and use nested or subform in
update to add more images.

David Sedeño

unread,
Jan 25, 2008, 3:31:12 PM1/25/08
to actives...@googlegroups.com
Thanks a lot Sergio for your patiente :)

I have put all this information in the Wiki, so others can do it more easly:

http://wiki.activescaffold.com/wiki/show/ActiveScaffold+with+Attachment_fu

Cheers

2008/1/25, sergio <ser...@ensanjose.net>:

talknightlife

unread,
Jan 28, 2008, 4:53:30 PM1/28/08
to ActiveScaffold : Ruby on Rails plugin
I've been trying to use Active Scaffold's built-in support for file-
column with no luck. I tried posting a question to this group twice
but the message never showed up in "Discussions", so nobody is ever
going to see it and help me. (Search for "Problem with file-column
bridge" to see the message if you're curious. Searching explicitly
for it is apparently the only way to see it.)

Frustrated with all of that, and with file-column apparently not
working, I'm interested in changing directions and trying out
attachment-fu instead. Especially since David has apparently provided
some guidance. Only problem: the link doesn't work. What's the
password to the wiki?

It seems almost like the entire universe is conspiring against my web
app ever being able to accept uploads! Argh!

David Sedeño

unread,
Jan 29, 2008, 10:46:07 AM1/29/08
to actives...@googlegroups.com
Well, the password is actsaspassword (is in one page on the wiki). You can also read the wiki in read only mode. The link in read only is:

http://wiki.activescaffold.com/wiki/published/ActiveScaffold+with+Attachment_fu



2008/1/28, talknightlife <si...@talknightlife.com>:

talknightlife

unread,
Jan 29, 2008, 11:59:15 AM1/29/08
to ActiveScaffold : Ruby on Rails plugin
On Jan 29, 10:46 am, "David Sedeño" <frim...@gmail.com> wrote:
> Well, the password is actsaspassword (is in one page on the wiki). You can
> also read the wiki in read only mode. The link in read only is:
>
> http://wiki.activescaffold.com/wiki/published/ActiveScaffold+with+Att...

Thanks for the link, David. I did manage to find that link myself
last night after some Googling, and I tried using attachment-fu with
Active Scaffold as you described. Many thanks for the writeup.

I set up two models just like in the wiki page and all I get is
mysterious nil object errors from deep within attachment-fu. Probably
something that I'm doing wrong but the errors don't help much to
figure out my problem.

My setup mirrors the wiki page, I'm using "Event" instead of "Person"
and "Flyer" instead of "Image", but other than that it's the same
exact setup:

in events_controller.rb:
class EventsController < ApplicationController
active_scaffold :events do |config|
config.columns.add :uploaded_data
config.create.multipart = true
config.create.columns = [:uploaded_data, :name]
config.nested.add_link("Flyers", [:flyers])
end
end

in flyers_controller.rb:
class FlyersController < ApplicationController
active_scaffold :flyers do |config|
config.columns.add :uploaded_data
config.columns.exclude :uploaded_data
config.create.multipart = true
config.create.columns = [:uploaded_data, :name]
config.list.columns = [:filename, :image]
end
end

in events_helper.rb:
module EventsHelper
def uploaded_data_form_column(record, input_name)
file_field_tag input_name
end
end

in flyers_helper.rb:
module FlyersHelper
def image_column(record)
image_tag record.public_filename(:thumb)
end
end

in event.rb:
class Event < ActiveRecord::Base
has_many :flyers
def uploaded_data
nil
end
def uploaded_data=(data)
self.flyers<< Flyer.new(:uploaded_data => data)
end
end

in flyer.rb:
class Flyer < ActiveRecord::Base
belongs_to :event
has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 5500.kilobytes,
:resize_to => '708x708>',
:thumbnails => { :thumb => '190x190>' },
:path_prefix => 'public/uploads'
validates_as_attachment
end

The mysterious error that I see when I press the "Flyers" button in
the "Events" controller:

ActionView::TemplateError (You have a nil object when you didn't
expect it!
The error occurred while evaluating nil.gsub) on line #10 of vendor/
plugins/active_scaffold/frontends/default/views/_list_record.rhtml:
7:
8: <tr class="record <%= tr_class %>" id="<%= element_row_id(:action
=> :list, :id => record.id) %>">
9: <% active_scaffold_config.list.columns.each do |column| %>
10: <% column_value = get_column_value(record, column) -%>
11:
12: <td class="<%= column_class(column, column_value) %>" >
13: <%= render_list_column(column_value, column, record) %>

/Users/rap/projects/venuedriver/vendor/plugins/attachment_fu/lib/
technoweenie/attachment_fu.rb:201:in `thumbnail_name_for'
/Users/rap/projects/venuedriver/vendor/plugins/attachment_fu/lib/
technoweenie/attachment_fu/backends/file_system_backend.rb:21:in
`full_filename'
/Users/rap/projects/venuedriver/vendor/plugins/attachment_fu/lib/
technoweenie/attachment_fu/backends/file_system_backend.rb:43:in
`public_filename'
/Users/rap/projects/venuedriver/app/helpers/flyers_helper.rb:3:in
`image_column'
/Users/rap/projects/venuedriver/vendor/plugins/active_scaffold/lib/
helpers/list_column_helpers.rb:11:in `send'
/Users/rap/projects/venuedriver/vendor/plugins/active_scaffold/lib/
helpers/list_column_helpers.rb:11:in `get_column_value'

That error doesn't seem to have anything at all to do with any code
that I wrote, so it's a pretty steep challenge to figure out WTF is
wrong. I don't even know where to start. If anybody has any
suggestions then I would greatly appreciate it.

talknightlife

unread,
Jan 29, 2008, 12:27:48 PM1/29/08
to ActiveScaffold : Ruby on Rails plugin
Before anybody spends any time trying to help me with my problem, I
wanted to mention that I found it. I wasn't getting anywhere with
that useless error from deep within the plugin code, but I did manage
to figure out (partly from typing it in the message above) that my
"Flyers" controller was failing because I gave it bad column names.

This fix to flyers_controller.rb got me past the error, because of
course my Flyer objects don't have a "name" like in your example:

class FlyersController < ApplicationController
active_scaffold :flyers do |config|
config.columns.add :uploaded_data
config.columns.exclude :uploaded_data
config.create.multipart = true
config.create.columns = [:uploaded_data]
config.list.columns = [:filename]
end
end

I still don't actually have attachments working but hopefully I can
take it from here. I just wanted to stop anybody from spending too
much time on trying to help me.

Tranquiliste

unread,
Feb 18, 2008, 3:24:13 AM2/18/08
to ActiveScaffold : Ruby on Rails plugin
Hello,

I have followed the wiki and it worked perfectly, except that tehre is
a small typo the code
def uploaded_data_form_column(record,input_name)
file_field_tag input_name
end

Should be in ImagesHelper rather than PersonHelper

On 25 jan, 21:31, "David Sedeño" <frim...@gmail.com> wrote:
> Thanks a lot Sergio for your patiente :)
>
> I have put all this information in the Wiki, so others can do it more easly:
>
> http://wiki.activescaffold.com/wiki/show/ActiveScaffold+with+Attachme...
Reply all
Reply to author
Forward
0 new messages