premailer rails not generating text part automatically - ruby-on-rails-3

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.

Related

Rails UserRegistrationsController not Inheriting from Devise::RegistrationsController

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!

binding.pry ignored by rails 3

I'm trying to debug my little app failing to create a Price because of an AssociationTypeMismatch. So I dig out pry, install, watch railscast and Josh's screencast and dig into the wiki.
I "cd" into the prices controller but that fails. I've put <% binding.pry %> into the new.html before the submit code but Rails says that the 'pry' method is unknown. pry is in my updated Gemfile and I restarted the server.
I put binding.pry into the create method of my prices_controller.rb and Rails happily breezes through it to throw the error I've already seen, not the pause, etc I was expecting.
Looking at the Price model, I'm not experienced enough to know what I should be looking for. What am I overlooking? thanx, sam
I have the exact same problem, my solution was to add pry-remote to my Gemfile, and call binding.remote_pry instead of binding.pry, open the terminal at your current project and execute pry-remote. happy debugging :)
It appears that in addition to the pry gem, I need the pry-rails gem as well. Now the binding.pry is recognized.
Instead of installing pry-rails you could just require 'pry' before the binding :-)

Rails Amazon S3 Paperclip/s3-swf-upload-plugin Associating attached files

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.

Rails 3 CSRF_meta_tag not functioning

I am in the process of upgrading my app from Rails 2.3 to Rails 3. I read that I need to insert
<%= csrf_meta_tag %>
in my layouts, which I did. Unfortunately, when I used ajax requests, I kept being logged out. After a little research, I found an older way was to add
$j(document).ajaxSend(function(e, xhr, options) {
var token =$j("meta[name='csrf-token']").attr("content");
xhr.setRequestHeader("X-CSRF-Token", token);
});
in my application.js file. It now works properly (It seems I actually don't need the csrf_meta_tag).
Is it normal I had to add these 4 lines of code in my application.js instead of just the csrf_meta_tag, or am I just missing something?
Firstly, you do need csrf_meta_tag. If you don't use it in your layout the csrf-token meta will not be generated then your application.js fix stops working.
The jquery-ujs gem (jquery-rails) should take care of this for you. It's possible the version you use have some bug. (I do remember there's a related bug in 3.0.x, but couldn't recall the exact issue). Try updating jquery-ujs and re-generate jquery (rails generate jquery:install), remove rails.js to see if the issue be fixed.
Bonus note: as of rails 3.1, csrf_meta_tag has been renamed to csrf_meta_tags, but the former one could still be used.
Please see jquery-ujs on github.

Cannot get devise_oauth2_canvas_facebook to work

I'm getting a "TypeError in Devise::FacebookConsumersController#callback: can't convert Hash into Integer" when I try to authenticate using Devise and devise_oauth2_canvas_facebook gem with the new Facebook API. Any ideas what can be the problem?
It look like mooktakim the creator of the devise_oauth2_canvas_facebook gem is not updating it anymore.
Here is his message on a pull request to that effect:
https://github.com/mooktakim/devise_oauth2_facebook/pull/9
He says that he is moving to Omnisocial
https://github.com/icelab/omnisocial#readme
This uses Omniauth which allows you to use logins from many different sources.
It might be better for you to move to Omniauth.