Rails 3.0.5
gem 's3_swf_upload', :git => 'git://github.com/nathancolgate/s3-swf-upload-plugin'
gem 'aws-s3'
gem 'awk-sdk'
gem "paperclip", :git => "git://github.com/thoughtbot/paperclip.git"
This is a "is it possible and how hard is it" question. I had a requirement to take in video submission to a website and store them on Amazon S3. Originally I was going to do this via paperclip. However, some one made me aware that we may eat up all our dinos since the file would first be uploaded to our app on heroku first.
Instead I went with the GEM s3-swf-upload-plugin. This is supposed to by pass our server and upload using javascript and flash. (If I am wrong on this please let me know but so far it seems to work as expected.) However, as far as I can tell I can't rename the file with out a fair bit of javascript and I don't think I can collect the URL of the file to link in my object.
What I would like to do: After the file is uploaded and before I save my object I would like to go out to S3 find the file, use paperclip to move/rename it (Using it's useful :path => ":class/:id/:filename") and then assigning the typical paperclip attributes so that I can link to the video in my object.
I have search around a bit today (I admit I have not search as long as I usually do before I come here but my time to get this done is limited) and I all can find is how to set it up normally. The s3-swf-upload-plugin has something which I think may be doing exactly what I need but I don't understand it enough to fit it into my code. https://gist.github.com/575842
If the Gist above is what I need does any one mind explaining what the important part do so I might understand and modify it appropriately? If it is not what I need is there something out there that would help? Thank you all for any help you can provide.
Related
Learning the ropes of AWS S3 and the sdk. Trying to use in in my Rails app via the aws-sdk gem. I was following this post:
Remove entire object directory tree using AWS-SDK
Luckily for me that I was playing around in my staging bucket. I created a folder test and uploaded an example.jpg image. From the rails console I ran (note the lack of {} brackets):
s3.delete_object(bucket: 'mystagingbucket', key: '/test/example.jpg')
=> #<struct Aws::S3::Types::DeleteObjectOutput delete_marker=true, version_id=nil, request_charged=nil>
then I go back into the web console to find my entire bucket empty. All my previously uploaded files, static assets, etc. all gone.
So I realize that I should turn versioning on and try this again to duplicate the issue. After some Googling I see the docs show the {} brackets.
Now I get:
s3.delete_object({bucket: 'mystagingbucket', key: '/test/example.jpg'})
=> #<struct Aws::S3::Types::DeleteObjectOutput delete_marker=true, version_id="blohAaXlnG2.RERnj_JT3zvQmAr8io48", request_charged=nil>
except that nothing happens and the file is not deleted. I have done some more Googling and I now see that it can take up to a few hours to see your files actually deleted so I will check back on the recent delete issues.
As for the bucket contents getting erased am I missing something here?
I'm pretty new to Rails, but followed the excellent suggestion/walkthrough here. I've gotten the creation of my two user types (Clients and Developers) to work successfully with Devise. However, I also want to allow both user types to edit some of their attributes after they are logged in. These attributes are also specific to their user types (client specific fields or developer specific fields).
To do this, I thought that I needed to create a custom update in user_registrations_controller which inherits from Devise::RegistrationController as would make sense. During my customization however, I realize within update I am unable to call other default methods from Devise::RegistrationController. As a sanity check, I overrode update with an exact copy of the update method as defined in the original Devise::RegistrationController and still had this issue.
More specifically, the error I receive is: undefined local variable or method 'account_update_params' for #<UserRegistrationsController:0x007fe4f0342d58>, despite account_update_params being a method in the inherited controller.
Is there a better way to edit the fields specific to my user types (client/developer) in Devise without having to customize update? Also, what is going on with this error here, as I believe I am inheriting from Devise::RegistrationController?
Any thoughts? Help and suggestions much appreciated! =)
Versions: Rails 3.2.12, ruby 1.9.3p249
After revisiting this, I found this related question. Though this post and top answer is specific to Rails 4, the solution can be found in the Gemfile.
Replace your devise gem include with
gem 'devise', :git => 'git://github.com/plataformatec/devise.git'
Simply doing gem 'devise' does not get this updated version, unfortunately. Hope this helps others!
I want to use premailer-rails to generate text part of email automatically.
gem 'hpricot'
gem "premailer-rails"
I'm not getting the text part when I look at the actual email.
It seems as if the gem is not enabled. Any idea why?
If the gem is not working, it may be because you are missing an initializer
Add this code in config/initializers/premailer_rails.rb
Premailer::Rails.config.merge!(preserve_styles: true, remove_ids: true)
Also
If you're using this gem outside of Rails, you'll need to call Premailer::Rails.register_interceptors manually in order for it to work. This is done ideally in some kind of initializer, depending on the framework you're using.
You can find this information on the gem's Github page https://github.com/fphilipe/premailer-rails.
On another note, they also recomend to use nokogiri instead of hpricot, seeing as the latter is no longer mantained.
I'm building a website for a rabbit farmer (let's pretend). This man keeps a close eye on his rabbits, and wants them all categorized. So I built him a RabbitCategoriesController, and added this line to my routes.rb
resources :rabbit_categories
The URLs are showing up as rabbit_categories, rabbit_categoriew/new, etc.
What if I want the URLs to look like rabits/categories rabits/categories/new instead? This is not a nested resource, I just want to change the way the URLs look.
Of course, if the resources were called "categories", I could do
namespace :rabbits do
resources :categories
end
Is there any way I can write that, but tell it to use the RabbitCategoriesController instead of the Rabbits::CategoriesController?
have you tried this, should work
resources :rabbit_categories, :path => "rabbits/categories"
See Rails Routing from Outside In for more details.
I've got google analytics setup on a rails project, and I've got "A single domain (default)" selected for the tracking options.
I've copied and pasted the js code into the layout for the application.
Now, if I use this locally, does analytics track the local use as well?
The reason I'm asking this is we've been running tests on our dev computers using rspec, and there seems to be a spike in the analytics. All these spikes also seem to show up as unique visitors.
I'd appreciate any insight on this.
Thanks!
Also, using a Google Analytics gem will automatically set some of these features for you. Here is a great way to do it:
Google Analytics and Rails in 5 EASY Steps:
If you are in Rails 3, I just found a great solution for doing Google Analytics in Rails apps.
(1) In your Gemfile:
group :production do
gem 'rack-google_analytics', :require => "rack/google_analytics"
end
(2) Bundle Install
(3) In your config/application.rb (put this in the class definition section - careful not to drop it in a module. I put mine right under "class Application"):
if Rails.env == "production"
config.middleware.use("Rack::GoogleAnalytics", :web_property_id => "UA-0000000-1")
end
(4) Initiate your Google Analytics account
(5) Copy and paste that funky web_property_id from Google's supplied code into the code from (3), replacing 'UA-000000-1'
That's it!
I originally found this solution here:
David Bock Article
I tried the gems but they didn't work; wouldn't spit out any code, etc. Seemed dumb for something so simple. So I ended up just doing this, in application.html.erb:
<% if Rails.env.production? %>
(GA JS Code Snippet)
<% end %>
Yes, it does track local visits as well.
You should probably use ruby conditional statement to exclude it for the local conneciton.
For example, at the bottom of the layout file
<% if !request.local? %>
Your source codes for Google Analytics
<% end %>
This way, Google Analytics will not be printed if connection is made from local.
In the google analytics admin, you can filter out visitors based on various attributes (e.g. ip address) This would also be a good idea to do.
Another option that I've done is add another analytics tracking account that you use for the dev/test environment so that you can test whether and how analytics are working.
This tutorial shows you how to set it up. I don't know why there's a gem for this.
Just put the code in a partial and render it in your application layout if rails.env.production?
http://aihuiong.com/post/452550136/google-analytics-and-rails-in-3-steps-and-less-than-5