I have an app that sends an email when a user signs up. I've got the emails to send successfully but the images are not getting sent. I'm hosting on Heroku and using Sendgrid to send emails.
Here's my signup_email.html.erb view:
<tr>
<td style="padding: 20px 0; text-align: center">
<img
src="<%= Rails.application.config.action_mailer.default_url_options[:host] %>assets/email/logo.png"
width="200"
height="50"
alt="logo"
border="0"
style="height: auto; background: #dddddd; font-family: sans-serif; font-size: 15px; line-height: 15px; color: #555555;"
/>
</td>
</tr>
This is not an issue where the browser hides images by default because I've tested on various browsers and tried to show images. The image path in the email shows: heroku-root/assets/email/logo.png
Here's the signup user_mailer.rb:
class UserMailer < ActionMailer::Base
default from: "App <welcome#app.com>"
def signup_email(user)
#user = user
mail(:to => user.email, :subject => "Thank you for joining!")
end
end
I've precompiled assets with rake assets:precompile so the logo is stored in public/assets/email directory.
The production.rb setting:
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
config.action_mailer.default_url_options = { :host => ENV['DEFAULT_MAILER_HOST'] }
config.action_mailer.delivery_method = :smtp
config.serve_static_assets = true
I've tried using the inline attachment method from the Rails documentation but emails weren't getting sent at all.
class UserMailer < ActionMailer::Base
default from: "App <welcome#app.com>"
def signup_email(user)
#user = user
attachments.inline["logo.png"] = File.read("#{Rails.root}app/assets/email/logo.png")
mail(:to => user.email, :subject => "Thank you for joining!")
end
end
In the view, I call the logo like this:
<%= image_tag(attachments['logo.png'].url) %>
With the method above the emails don't get sent at all and I get the error that it couldn't find the file logo.
You should just be able to use the regular old <%= image_tag("logo.png") %> helpers just like you would use in your views. You may need to set your asset_host so that it includes a full URL for the images in the emails since they aren't displayed in the browser under your domain.
# I believe these should do the trick:
config.action_controller.asset_host = 'http://localhost:3000'
config.action_mailer.asset_host = config.action_controller.asset_host
I'm following along with the Angular/Rails tutorial at Thinkster and I've run into an issue which seems to be most likely be Angular-related. Everything works just fine until I get to the Angular Routing section. Simply put, the inline templates within the <script> tags do not load in the <ui-view></ui-view> element. I originally thought this may be due to having opened the page locally as a file rather than having it loaded from a server, but the same problem persists even after integrating Rails (using an older version of Sprockets, as pointed out in this similar but unrelated issue).
When I load the index page in either the browser as a file or as a URL when running the Rails server, I've inspected the HTML and, sure enough, the only thing it shows in the code are the divs and an empty <ui-view> element, indicating something just isn't adding up correctly. I've tried various things, including:
Using the newest version of ui-router (0.2.15 at this writing) rather than the version in the tutorial
Using <div ui-view></div> instead of <ui-view></ui-view>
Changing the value of 'url' in the home state to 'index.html', including using the full path to the file (file:///...)
Putting the contents of the inline <script> templates into their own files (without the <script> tags, of course) and specifying the 'templateUrl' field using both relative and full paths
Trying both Chrome and Firefox just to be extra certain
None of these things have worked, even when accessing http://localhost:3000/#/home when the Rails server is running after having integrated Angular into the asset pipeline in the Integrating the Front-end with the Asset Pipeline section of the tutorial. Indeed, the route loads but does not show anything more than a completely blank page with a lonesome and empty <ui-view> element when inspecting the HTML using Chrome's dev tools.
Given that the issue seems to occur even before the Rails portion, it does seem like something to do with Angular itself, but I've got no clue what's going on, especially since I've followed along to the letter.
I'm using Bower to manage the Angular dependencies and the HTML does show that the Angular javascript files in both the app/assets/javascripts directory and in the vendor/assets/bower_components directory are being loaded properly in the <head> section, so everything seems to be okay on the asset pipeline integration.
Versios I'm using:
Rails: 4.2.3
Ruby: 2.2.1p85
Angular: 1.4.3
ui-router: 0.2.15
The code I've got for the major moving parts is below:
app/views/layouts/application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Test App</title>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>
<%= csrf_meta_tags %>
</head>
<body ng-app="testApp">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<ui-view></ui-view>
</div>
</div>
</body>
</html>
app/assets/javascripts/app.js
angular.module('testApp', ['ui.router', 'templates']).config(['$stateProvider', '$urlRouteProvider', function($stateProvider, $urlRouteProvider) {
$stateProvider
.state('home', {
'url': '/home',
'templateUrl': 'home/_home.html',
'controller': 'MainCtrl'
})
.state('posts', {
'url': '/posts/{id}',
'templateUrl': 'posts/_posts.html',
'controller': 'PostsCtrl'
});
$urlRouteProvider.otherwise('home');
}]);
app/assets/javascripts/application.js
//= require angular
//= require angular-rails-templates
//= require angular-ui-router
//= require_tree .
app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
respond_to :json
def angular
render 'layouts/application'
end
end
config/routes.rb
Rails.application.routes.draw do
root to: 'application#angular'
end
app/assets/javascripts/home/mainCtrl.js
angular.module('testApp').controller('MainCtrl', ['$scope', 'posts', function($scope, posts) {
$scope.posts = posts.posts;
$scope.addPost = function() {
if (!$scope.title || $scope.title === "")
return;
$scope.posts.push({
'title': $scope.title,
'link': $scope.link,
'upvotes': 0,
'comments': [
{'author': 'Some Person', 'body': 'This is a comment.', 'upvotes': 0},
{'author': 'Another Person', 'body': 'This is also a comment.', 'upvotes': 0}
]
});
$scope.title = "";
$scope.link = "";
};
$scope.incrementUpvotes = function(post) {
post.upvotes++;
};
}]);
app/assets/javascripts/posts/postsCtrl.js
angular.module('testApp').controller('PostsCtrl', ['$scope', '$stateParams', 'posts', function($scope, $stateParams, posts) {
$scope.post = posts.posts[$stateParams.id];
$scope.addComment = function() {
if($scope.body === '')
return;
$scope.post.comments.push({
'body': $scope.body,
'author': 'user',
'upvotes': 0
});
$scope.body = '';
};
}]);
app/assets/javascripts/posts/posts.js
angular.module('testApp').factory('posts', ['$http', function($http) {
var o = {
'posts': []
};
o.getAll = function() {
return $http.get('/posts.json').success(function(data) {
angular.copy(data, o.posts);
});
};
return o;
}]);
If any other code is required to help uncover the problem, please let me know and I'll supply anything requested.
it seems that the angular-ui-router is incompatible with the new Rails sprockets. To fix this, add this earlier version of sprockets to your gemfile:
gem 'sprockets', '2.12.3'
And then run bundle update sprockets.
This was answered a few times in other similar questions, like the one below:
Angular Rails Templates just not working
$urlRouteProvider in my code should've been $urlRouterProvider. Be sure to double-check everything, folks, and make good use of the console!
I'm testing a page that have various embedded youtube videos. Capybara-webkit is extremely slow to load and test that page, so I need to disable iframes load for that page.
The iframe looks like that:
<iframe class="embedly-embed" src="//cdn.embedly.com/widgets/media.html?src=http%3A%2F%2Fwww.youtube.com%2Fembed%2FKxu2A7-uBus%3Ffeature%3Doembed&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DKxu2A7-uBus&image=http%3A%2F%2Fi.ytimg.com%2Fvi%2FKxu2A7-uBus%2Fhqdefault.jpg&key=7c4c130437b3403ab254d76c5015b5a5&type=text%2Fhtml&schema=youtube" width="854" height="480" scrolling="no" frameborder="0" allowfullscreen=""></iframe>
I tried two approaches:
Blacklisting the url:
Capybara.register_driver :webkit do |app|
# Disabling useless resources loading from capybara
driver = Capybara::Webkit::Driver.new(app)
driver.browser.url_blacklist = [
'//cdn.embedly.com/*',
'//cdn.embedly.com/widgets/*',
'http://cdn.embedly.com/widgets/*'
]
driver
end
Set all iframes as display: none;
(In application.html.erb)
<% if Rails.env.test? %>
<style>iframe {display:none}</style>
<% end %>
Both of them failed...
Any ideas?
I am trying to configure omniauth-facebook to fetch user friends.
This is my configuration:
ActionController::Dispatcher.middleware.use OmniAuth::Builder do
provider :facebook, "xxxxxx", "xxxxxxxx",
:info_fields => 'friends'
end
I am using Rails 2.3.
I am using this code in view:
<div id="contacts">
</div>
<script type="text/javascript" charset="utf-8">
$('contacts').innerHTML = '<%= request.env['omniauth.auth'].keys %>';
</script>
I am not sure why the script is not being executed, but when I copy:
$('contacts').innerHTML = 'infouidcredentialsextraprovider';
in console after page has loaded it works replacing content of div with that text.
There is no error message in browser console.
Why script does not get executed? I tried with console.log too, and I had no luck.
The info_fields option is still new and so you will have to wait for a new release of the omniauth-facebook gem.
In the meantime, you can try using the master branch by changing your Gemfile to:
gem 'omniauth-facebook', :github => 'mkdynamic/omniauth-facebook'
As for debugging, you can get the information returned from facebook by adding the following as the first line of your callback controller:
raise request.env["omniauth.auth"].to_yaml
Now try to login and you'll be able to take a good look at the hash of nested hashes returned.
Assets are working fine for my web views, but for some reason my Mailer doesn't use the asset pipeline. I am trying to use an image_tag in my mailer view:
=link_to image_tag("logo.png")
However, that renders as
<img alt="logo" src="http://mydomain.com/assets/logo.png">
instead of
<img alt="logo" src="http://mydomain.com/assets/logo-xxxxxxxxx...png">
Am I missing something here?
My settings are:
config.action_mailer.default_url_options = { :host => config.domain }
config.action_mailer.asset_host = "http://" + config.domain
Thank you!
Try to put in your mail template the following instead of the link_to ( the link_to makes no sense because you link here your image to nothing, and I don't see the a href as output in your html) :
= asset_path("logo.png")
also put in your specific environment file :
config.action_mailer.default :content_type => "text/html"
Like this you are sure that you always use HTML as default content type. If u are using images in the mails it is better to put it as html.