-------
Firstly, to install and use paperclip and aws-s3 I've got them both in
by Gemfile:
gem 'paperclip', :git => 'git://github.com/thoughtbot/paperclip.git'
gem 'aws-s3', :require => 'aws/s3'
from directory of rails app I then type "Bundle install" (enter)
I've got require 'aws/s3' in the model and the controller, and neither
throws up an error.
I've registered with aws-s3, and tested that from console
Is this all I need to do to install them both?
-----------
Assuming I've got them installed correctly how do I use them...
I keep getting the error message: undefined method `stringify_keys' for
#<String:0x1035803c8> when I try to save and then view the image.
This goes away when I remove the line :storage => :s3 from the model.
My model looks like this:
---------
class EdTenEvent < ActiveRecord::Base
require 'aws/s3'
has_attached_file :photo,
:styles => { :thumb => "100x100#", :small => "150x150>" },
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => ":attachment/:id/:style.:extension",
:bucket => 'tenevent'
end
---------
When I create a new 'EdTenEvent' the controller looks like this:
-----------
def create
@ed_ten_event = EdTenEvent.new(params[:ed_ten_event])
if @ed_ten_event.save
flash[:success] = "new event created"
redirect_to ed_ten_events_path
else
@title = "New Event"
render 'new'
end
end
-----------
and the form for adding new 'EdTenEvents' looks like this:
-----------
<%= form_for @ed_ten_event , :html => { :multipart => true } do |f| %>
<%= render 'shared/error_messages', :object => f.object %>
<div class="field">
<%= f.label :photo %>
<%= f.file_field :photo%>
</div>
<div class="actions">
<%= f.submit "Add Event" %>
</div>
<% end %>
Index.html.erb looks like this:
---------
#... make table
<% @ed_ten_events.each do |event| %>
<tr>
<td><%= image_tag event.photo.url(:thumb) %>
#... add more things to table
</table>
---------
I've got my s3.yml setup in config
----------
access_key_id:MYKEYHERE
secret_access_key:MySuperSecretKeyHere
bucket:tenevents
-----------
As I said before, I keep getting the error message: undefined method
`stringify_keys' for #<String:0x1035803c8>
This goes away when I remove the line :storage => :s3 from the model.
Not sure what I'm doing wrong, just trying to do the most basic thing,
store 1 photo!
Any pointers to turorials would be great although I've read about 10 and
they all seem to think this should work!
Any help appreciated
Mike B
--
Posted via http://www.ruby-forum.com/.
> As I said before, I keep getting the error message: undefined method
> `stringify_keys' for #<String:0x1035803c8>
>
> This goes away when I remove the line :storage => :s3 from the
> model.
You might need to load s3 earlier than in the model you're using it
in. Maybe load it in the same time frame that Paperclip does, back in
the environment.rb or if that's different in Rails3, then wherever it
gets done there. Maybe try loading it before Paperclip.
Walter
uninitialized constant AWS::S3::NoSuchBucket
I've set up my s3.yml file now to have the 3 buckets production,
development and test.
-------------
development:
bucket: teneventsdevelopment
access_key_id: key1
secret_access_key: key2
test:
bucket: teneventstest
access_key_id: key1
secret_access_key: key2
production:
bucket: tenevents
access_key_id: key1
secret_access_key: key2
-------------
class EdTenEvent < ActiveRecord::Base
has_attached_file :photo,
:styles => { :thumb => "100x100#", :small => "150x150>" },
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => "/:style/:id"
end
-------------
Gemfile etc is as above...
has anyone had the error 'uninitialized constant
AWS::S3::NoSuchBucket'??
anyone got rid of it???
has anyone managed to get a rails3 app working with paperclip and s3?
any help apprecirated.
Mike
Walter
> --
> You received this message because you are subscribed to the Google
> Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-
> ta...@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
> .
>
I wrote up how to do this set up here http://www.arailsdemo.com/posts/15
Hopefully that will get you going.
Michael Baldock wrote in post #958147:
> Thanks for the help Walter, I tried what you said, putting them in a
> different order, still doesn't quite work, although some progress, got a
> different error message now!:
>
> uninitialized constant AWS::S3::NoSuchBucket
>
--
Posted via http://www.ruby-forum.com/.
@Walter - I'll have a look through the comments at the git page to see
if I can find anything about specific paperclip versions working with
rails3 / s3, and the same for aws-s3, thanks for the tip!
@ArailsDemo A. - That turoial looks really good, I'll try and go back
and do the whole thing one day! I have a couple of questions regarding
the paperclip / s3 part.
1. - Your model 'Resources' has the line
t.references :attachable, :polymorphic => true
is this important for being able to attach photos?
2. I'm inputting my photos in a different way, I have the lines:
<%= f.label :photo %>
<%= f.file_field :photo%>
Whereas you have:
= resource_f.input :attachment, :label => 'File'
I've tried substituing your way, and the 'new' page returns the error
undefined method `input' for...
Is this crucial in your setup?
3. I keep coming back to the line
:path => "/:style/:id"
Which in your tutorial is
:path => "/:style/:filename"
Every example seems to have a slightly different line here, what is this
referring to? Is this the structure of me s3 account? is 'style' the
paperclip reference for 'thumb / small / post' etc? Where do you get the
word ':filename' from??
Thanks again for you help, and a great tutroial.
Mike
2. You're markup should work. On the website, I'm using HAML as a
replacement for ERB. Also, I'm using the 'simple form' gem. So my markup
is going to look different than yours. Plus, I'm using a nested form.
3. The :path is the file path that file will be placed in your S3
account.
In your case, you specified
:styles => { :thumb => "100x100#", :small => "150x150>" }
So when you upload a file, paperclip will generate these two image
styles for you as separate files. If the original file was bigger than
both of these styles, then you'll also have a third 'original' file.
If you have
:path => "/:attachment/:id/:style.:extension"
your S3 file path will be something like '/photo/1/thumb.png'
If you used
:path => "/:style/:id"
your S3 file path would be '/thumb/1'. This won't work because it's not
specific enough. You'll just keep overwriting the same file. ':filename'
is automatically available for you to use because each upload has to
have a filename.
If you're using Firefox, I recommend the 'S3Fox' add-on that will allow
you to browse your S3 account through Firefox.
Still getting the same error, now using the path:
:path => "/:attachment/:id/:filename.:extension"
Another thing I noticed, when I sign in to aws-s3 through the rails
console, like this:
Base.establish_connection!(:access_key_id...
I get the message
#<AWS::S3::Connection:0x1035886e0 @http=#<Net::HTTP s3.amazonaws.com:80
open=false>,
which doesn't seem good, however following this I can still access my s3
buckets. Service.buckets returns a complete list.
is the ...open=false> message normal??
Thanks
Also, in the s3.yml file, do you have things in quotes?
development:
bucket: 'teneventsdevelopment'
access_key_id: 'asdfa324234'
secret_access_key: 'qwer2342'