Config/environment.rb

I just recently started using the file_column plugin. I have an easy
time getting it to upload files, but I can seem to get it to work on the
view. I get the error “undefined method `image_relative_path’”.

I read the documentation and at one point it says to “require
[rails_file_column.rb] file from your ‘config/environment.rb’ (after
rails has been loaded) to integrate the file_column extension into
rails.” Considering that I’ve followed pretty much every other step (I
think), I figure that this may be my problem. My question is what is the
proper syntax to require a file in the environment.rb file?

Another thing that doesn’t have to much to do with the environment.rb is
that ever since I started using the file_column plugin I’ve been getting
this “Loaded suite dispatch.cgi Started Finished in 0.00018 seconds. 0
tests, 0 assertions, 0 failures, 0 errors” at the bottom of my
page…Anyway to make this not show up?

Thanks.

HI Steve,

2007/2/18, Steve K. [email protected]:

I read the documentation and at one point it says to “require
[rails_file_column.rb] file from your ‘config/environment.rb’ (after
rails has been loaded) to integrate the file_column extension into
rails.”

Did you put the plugin under /vendor/plugins/? Then you needn’t any
requirements of this Plugin in your environment.

Im my view, I have something like

<%= image_tag url_for_file_column(“product”, “image”), {:class =>
“produktbild” } %>

HTH,
Beate

Beate P. wrote:

HI Steve,

2007/2/18, Steve K. [email protected]:

I read the documentation and at one point it says to “require
[rails_file_column.rb] file from your ‘config/environment.rb’ (after
rails has been loaded) to integrate the file_column extension into
rails.”

Did you put the plugin under /vendor/plugins/? Then you needn’t any
requirements of this Plugin in your environment.

Im my view, I have something like

<%= image_tag url_for_file_column(“product”, “image”), {:class =>
“produktbild” } %>

HTH,
Beate

I did install it in /vendor/plugins/, and in the view I put the
equivalent to your <%= image_tag url_for_file_column(“product”, “image”)
%> however I’m not sure what the :class is for, unless it refers to the
CSS class?

Anyways this is the code for the view:

<% odd_or_even = 0 for product in @products odd_or_even = 1 - odd_or_even %> <% end %>
<%= image_tag url_for_file_column("product", "image_url") %> <%= h(product.name) %>
<%= h(truncate(product.description, 80)) %>
$<%= sprintf("%0.2f", product.price) %>

<%= product.rebate %>% off!

Offer Ends: <%= product.end_date.strftime("%d-%m-%y") %>


<%= link_to 'Show', :action => 'show', :id => product %>
<%= link_to 'Edit', :action => 'edit', :id => product %>
<%= link_to 'Delete', {:action => 'destroy', :id => product}, :confirm => 'Are you sure you want to delete this Product?', :post => true %>

I’ll get this as an error:

“You have a nil object when you didn’t expect it!
The error occured while evaluating nil.image_url_relative_path”

Thanks again.

I encounter the same problem. What I did is change
<%= image_tag url_for_file_column(“product”, “image_url”) %>
to
<%= image_tag url_for_file_column(product, “image_url”) %>

and it works.

This is inspired by Jason S.'s post above, in ‘file_column_helper.rb’,
it will check if
the first parameter is a string or symbol, and tries to get the object
from it.

Since in your case, product is already an obj, you can just pass it in
directly.

-Michael
Claim: I don’t read gmail.

i had the same problem when i first tried file_column. i figured it
out by reading through ‘file_column_helper.rb’ that is installed with
the plugin in the lib directory. here’s what i found:

 object = instance_variable_get("@#{object.to_s}")

basically it gets a reference to the INSTANCE variable that is being
referred to by the first string you pass to url_for_file_column.

this means that in your case you need a variable named “@product” that
holds a reference to the product you’re trying to display the image
of. For instance, just try adding this to the top of your template and
see what happens.

<% @product = product %>

a cleaner solution would probably be to set this instance variable
somewhere inside the controller that renders your template code.

hope that helps,
-jcs