resource_url generating wrong url - ruby-on-rails

I have a rails app in a subdirectory of my server, something like www.domain.com/sub
I need to send an url by e-mail, so I tried to use "resource_url" but it generates a link like www.domain.com/resource_path, where should be wwww.domain.com/sub/resource_path.
How can I solve this ?
Thanks!

In Rails 2.3.8 you can add a line like this to your config/environments/production.rb
ActionController::Base.relative_url_root = "/sub"
I am not sure what the equivalent is for Rails 3, but see this question if that is what you are using:
What is the replacement for ActionController::Base.relative_url_root?

Related

How can I modify `gem kaminari` pagination links?

I'm doing a Rails application with gem 'kaminari'.
Like in the given screenshot below,
all links in generated pagination starts with
localhost:5000
but i need to modify it and change,
localhost:5000 to something like => https://new_domain and the rest of the url to follow....
Or set the HOST like in default_url_options.
Please help!
If you want customize look in kaminari first generate pages which kaminari. Run below generator
rails g kaminari:views default
then edit the partials in your app's app/views/kaminari/ directory.

Rails 4, Paperclip, S3 wrong url path

My heroku + Rails 4 + paperclip w/ AWS s3 is generating the wrong path for the image file.
This is the url paperclip is generating...
http://s3.amazonaws.com/travelquotesys/companies/logos/000/000/001/original/index.jpg%3F1416856406
It should be
http://s3.amazonaws.com/travelquotesys/companies/logos/000/000/001/original/index.jpg?1416856406
For some odd reason paperclip is generating the %3F instead of ? I don't know why it does that. I have a few Apps running on Heroku and this is the only one with this problem.
Your issue is related to a recent commit which doesn't properly escape the timestamp. A temporary workaround is to disable the timestamp while a fix is worked-out.
company.logo(:original, timestamp:false) # or whatever style you're using
Or you can disable this globally by putting the following line within your config/initializers/paperclip.rb file.
Paperclip::Attachment.default_options[:use_timestamp] = false
The issue is that Paperclip is escaping the url, so the character ? is escaped to %3F. To solve this issue add the following option to the S3 configuration:
escape_url: false
Hope it helps!

Generate HTML page using rails without a webserver

is possible to generate an HTML page using Ruby on Rails framework without using a webserver?
I want do something like this:
html = RailsHTMLGenerator.generate('path/to/rails/root', '/posts/540')
puts html
The first parameter is the Rails.root, the second is the HTTP path, and the function return the HTML of that page as string.
Someone can tell me how to do this? Ty.
I've found a solution:
require '/path/to/application.rb'
app = APPName::Application.initialize!
session = ActionDispatch::Integration::Session.new(app)
session.get '/'
puts session.body
Well, you can do that from the Rails console
app.get '/foo'
This is how the console is initialized in case you want to try this approach:
https://github.com/rails/rails/blob/master/railties/lib/rails/commands/console.rb

rails 3.1 - simple_captcha doesn't generate image

I am trying to use simple_captcha on my application but it doesn't seem to produce an image on my dev machine. 1.8.7, rails 3.1 here. If I attempt to visit the image URL i get an error "cannot generate tempfile `'".
Any ideas? I 'd like some help since I don't want to use recaptcha. thanks!
The error you get can be fixed by setting an explicit tmp_path by adding an initializer to config/initializers/:
SimpleCaptcha.setup do |captcha_config|
captcha_config.tmp_path = Rails.root + 'tmp'
end

Ruby on Rails Directory Path

I need to print Ruby on Rails complete url in my application. in details
with RAILS_ROOT I m getting a url like this
D:/projects/rails_app/projectname/data/default.jpg
But for my application I need a path like this
http://localhost:3000/data/default.jpg
Please help me to solve this issue. I am using Rails 2
Thanks
Today we use URI. Simply require the library and you will be able to parse your current dynamic and static URI any way you please. For example I have a function that can read URI parameters like so...
#{RAILS_ROOT}/app/helpers/application_helper.rb (The literal path string of the file depicted below)
def read_uri(parameter)
require 'uri'
#raw_uri = URI.parse(request.original_fullpath)
#uri_params_raw = #raw_uri.query
if #uri_params_raw =~ /\=/
#uri_vars = #uri_params_raw.split('=')
return #uri_vars[parameter]
end
return false
end
This should split all URI parameters into an array that gives the requested (numeric) "parameter".
I believe that simply the URI.parse(request.original_fullpath) should work for you.
I come from using a minimum of rails 4.2.6 with this method so, I hope it works for anyone who might view this later on. Oh, and just as a disclaimer: I wasn't so wise to rails at the time of posting this.

Resources