I am using premailer, and on my local machine I get links like this in the mail notes:
file://localhost/assets/header_logo.png
instead of
http://localhost:3000/assets/header_logo.png
How do I configure premailer so that the url is correct while in development?
I tried adding
Premailer::Rails.config.merge!(base_url: "http://localhost:3000")
to my development config file, but the server barfs saying there is no method Premailer::Rails.config.
I also did this:
config.action_mailer.default_url_options = {:host => 'localhost:3000'}
to no avail...
So the problem was that I was still using the premailer-rails3 gem, but reading the premailer-rails doc. Just updating the gem to premailer-rails fixed the issue.
For the archives... you can also put this into say config/initializers/premailer.rb and it will pick up whatever you've set for ActionMailer...
Premailer::Rails.config.merge!(
:base_url => "http://#{ActionMailer::Base.default_url_options[:host]}"
)
Related
In the env.rb to use Capybara you should setup Capybara.app = something
Middleman is based on sinatra so I was thinking to use Sinatra::Application but gives an error
Anyone know what should be put to set up Capybara in the proper way?
Although I've recently stated this answer in the (recently closed) GitHub issue that #bhollis gave, I should fill in the answer here as well in keeping with the spirit of StackOverflow.
In a spec_helper.rb file added to a spec folder in the root of your Middleman project, the assignment I've used is Capybara.app = Middleman::Application.server.inst - however, I configure it a little bit too like so:
Capybara.app = Middleman::Application.server.inst do
set :root, File.expand_path(File.join(File.dirname(__FILE__), '..'))
set :environment, :development
set :show_exceptions, false
end
A full example of this using RSpec can be found here.
The answer will eventually be at https://github.com/middleman/middleman/issues/895
Since I am currently using nginx to serve public/uploads only in subdomain assets, and also I am using the client side template(eco) to render the image (so I cannot use image_tag or image_url helper method provided by rails), I need to set the model.image_url (which provided by carrierwave) to return url with same domain.
Here is what I had tried: (in config/initializer/carrierwave.rb)
CarrierWave.configuration do |config|
config.assets_host = "http://assets.lvh.me:3000"
end
But when I try this setting then the rails popup an error message:
undefined method `assets_host=' for CarrierWave::Uploader::Base:Class (NoMethodError)
Since the README of carrierwave has this description of setting but only in fog section, so I'm wondering that is this function only work while using fog? Or did I miss anything?
Thanks for help
should use asset_host ( version > 0.7.0)
see chnage commit on github
https://github.com/jnicklas/carrierwave/commit/7046c93d6b23cffef9f171a5f7f0dd14267a7057#lib/carrierwave/uploader/configuration.rb
CarrierWave.configuration do |config|
config.asset_host = "http://assets.lvh.me:3000"
end
In later versions this changed to
CarrierWave.configure do |config|
...
end
Still can't get this working...Rails 3.1.3, Ruby 1.9.2 on Heroku's Cedar Stack.
Trying to use https://github.com/jtrupiano/rack-rewrite to make http://domain 301 redirect to http://www.domain to no luck (app works, but no redirects happen at all).
/config/initializers/rack_rewrite.rb (MyAppName is actually the correct name, domain.com is actual domain):
MyAppName::Application.config.middleware.insert_before(Rack::Lock, Rack::Rewrite) do
r301 %r{.*}, 'http://www.domain.com$&', :if => Proc.new {|rack_env|
rack_env['SERVER_NAME'] != 'www.domain.com'
}
end
Added to Gemfile:
gem 'rack-rewrite'
Did "gem install rack-rewrite", "bundle install".
No luck.
Any ideas?
UPDATE:
I have figured out PART of the problem. Since I'm just trying to serve "index.html" and it's "/style" folder, it appears that having "index.html" in "/public" overrides the rack-rewrite. If I remove "index.html", the rewrites work...but now I don't know where to put the files, or set up the routes.rb to direct to the index.html page by default...any help?
change
rack_env['SERVER_NAME'] != 'www.domain.com'
to
rack_env['SERVER_NAME'] == 'domain.com'
I think that maybe env["SERVER_NAME"] could be an internal dns in this case like 'app7009.intra.foo'. I do some stuff with domains in middleware in heroku: I look at both env['REQUEST_URI'] and env['PATH_INFO'], mainly because the POW-server I use locally doesn't set REQUEST_URI. It's a bit different how different servers populate the env hash, I wish this URL request part would be more standard with something like rack.
env['REQUEST_URI'] !~ /www.domain.com/
I'm new to this so I have no logical explanation as to why it works but it worked for me when I put the codes in config/application.rb instead of a new file /config/initializers/rack_rewrite.rb.
Whenever I send out emails in development mode, it does not put the localhost:3000 in the url. Is there any way I can configure this site-wide?
I have tried the following:
ActionMailer::Base.default_url_options[:host] = "localhost:3000"
inside of an initializer, but it has no effect.
I have also tried this in 'development.rb':
config.action_mailer.default_url_options = {:host => 'localhost:3000'}
Help?
(as in the comments to the question, so that the question can be answered)
Make sure you use the _url helpers in your Mailer views, because _path will only output relative urls (i.e. without the hostname).
I’m having some problems with John Guenin's x_sendfile (http://john.guen.in/past/2007/4/17/send_files_faster_with_xsendfile/).
When coding the download of a PDF file, I’m using the following code:
def send_the_file(filename)
xsendfile (“#{Rails.root}/doc/” + filename, :type => ‘application/pdf’)
end
but I only get 1 byte downloaded. This usually happens if the filename is not absolute (hence the #{Rails.root} being added. I’ve also checked that the file has the necessary permissions. This is failing both on localhost and my prod site.
Any ideas what I'm doing wrong?
TIA,
Urf
What version of Rails are you using? If you're on 2.1 or later, the X-Sendfile option is built into Rails' send_file method.
send_file 'filename', :x_sendfile => true
Otherwise, are you sure that mod_xsendfile has been installed and configured correctly?
You may want to make sure that your are actually using a web server that supports xsendfile. If you are dev mode you probably aren't and it may fail.
Try to set in apche httpd.conf file
XSendFileAllowAbove on