Rails 4 - ActiveAdmin - Redactor - Heroku -- has no method 'redactor' console error - heroku

I've been trying to tackle this all morning. Locally, this setup works just fine. I am not using the redactor-rails gem because this is a rails 4 app and it doesn't support it. I have moved the redactor.css and redactor.js calls from the active_admin initializer file to be required in my actice_admin.js.coffee and active_admin.css files because on Heroku, it could not find the path. Now, when firing up the page that should be displaying redactor, I get has no method 'redactor' in the console.
I'm at a loss. I've read up on precompiling assets and the how the pipeline works, but it doesn't seem like I'm doing anything out of the ordinary here.
So how can I deploy to Heroku without this error?

Ok, so I seemed to have disregarded an important task. After thinking about precompilation a bit more I remembered I had been told to run
RAILS_ENV=production bundle exec rake assets:precompile
before. After running that again, it precompiled the active_admin.css and active_admin.js.coffee files which had the new require's in it. Viola!
Hope this helps someone else in the future.

Related

Rails, production environment exception page shows in development environment

I'm running Rails 4.2.0.beta and am having a weird issue; instead of the usual Rail’s page displaying exceptions in development mode, like so:
I get the following:
This page appears with any exception.
I have double checked that I'm under development mode and that 'consider_all_requests_local' is set to true in config/environments/development.rb.
I noticed I'm receiving the following error when I hit an exception
" ERROR Rack::Lint::LintError: Response body was given for HEAD request, but should be empty
/Users/Rali/.rbenv/versions/2.2.0-dev/lib/ruby/gems/2.2.0/gems/rack-1.6.0.beta/lib/rack/lint.rb:20:in `assert'"
I assume it's somehow related.. Any ideas?
Sorry for digging out a month-old question but if there is anyone with same issue (like me), though with version 4.2.0.rc1 I fixed it by removing gem 'web-console' from Gemfile which is by default added when generating new application.
Removing gem 'web-console' also solved this issue for me in Rails 5.1, for anyone stumbling into this issue 4 years later...

How can I set up a download link to a pdf in rails 3.2?

I'm new with Rails and I'm having trouble understanding why the following error occurs. I have a page where I've linked a pdf file and some images for download.
In the view:
link_to( image_tag('image.png'),:controller=>'home',:action=>'download', :file_name => 'image.pdf') %>
In the controller:
def download
send_file "#{RAILS_ROOT}/assets/pdf/#{params[:file_name]}", :type=>"text/pdf"
end
When I try to download the file in the development environment I get the following error:
No route matches [GET] "/assets"
I've tried changing the path to the file and searching on google and SO. I imagine this must be a relatively simple fix and probably has to do with the asset pipeline but if someone could point me in the right direction, I'd be very happy.
Hey there I ran into this issue myself and the solution for me (rails 2.0.2) was to put the pdf file into the public directory of your application and make a direct link www.yoursite.com/my.pdf this will execute the download right away.
Why is this?
well once you deploy your app the rake assets:precompile will be ran and therefor the assets will appear in your public directory.
You can also do this local by running
$:. rake assets:precompile RAILS_ENV="development"
Although I would not advice commiting these files.

Paperclip routing error in Rails 3.1: only applies to new images

I am having essentially the same problem as this questioner: Paperclip routing error. The server gives a 404 for a static file (which is present!), so Rails gets called and then there is a routing error.
My Rails 3.1 app uses paperclip to attach files, but when serving files in production the following error is logged by Rails:
Started GET "/system/images/9/thumb/Large%20image.jpg?1320149338" for [...]
ActionController::RoutingError (No route matches [GET] "/system/images/9/thumb/Large%20image.jpg"):
Corresponding to an NGINX access log entry:
"GET /system/images/9/thumb/Large%20image.jpg HTTP/1.1" 404 728 "-" [...]
So, a few observations:
This didn't happen in the past, and past images with almost identical URLs still work, e.g.: /system/images/1/thumb/StoneSkimming%20Demyhb%20Art%203.jpg is served correctly.
The image files were uploaded, and converted by ImageMagick, correctly - I have verified all the expected files are in the right place, and are valid JPEGs with the right image in them.
Permissions for the files are all as expected, and match the files that still work.
The entries in the database for the relevant model look correct.
Adding/removing the query string, or putting the URL directly into the browser gives the same result as the embedded <img> tag: the image is not found.
Can anyone point me in the right direction here? I am having trouble working out how to test/debug this because the error is not universal across the app.
I am using Capistrano to deploy, so /public/system is a symlink to the shared directory. My instinct is that this is not the problem though, as older images in the same location work just fine.
I managed to solve problems with paperclip when deploying with capistrano to production by adding to capistrano deploy config:
namespace :deploy do
desc "build missing paperclip styles"
task :build_missing_paperclip_styles, :roles => :app do
run "cd #{current_path}; RAILS_ENV=production bundle exec rake paperclip:refresh:missing_styles"
end
end
after("deploy:update_code", "deploy:build_missing_paperclip_styles")
Probably there is better solution.

Rails 3.1.1 getting broken image on image assets

I'm missing something with the asset pipeline functionality. Things work fine in development and I move to run in production environment and all hell breaks loose!
So I have an image in app/assets/images named "logo.png"
I precompile (RAILS_ENV=production rake assets:precompile) and I can verify that in public/assets there now exists both a logo.png and logo-5fa60e416f495e562c56a5087fe696dc.png
I then run in production rails s thin -e production
But I get a broken image
GET http://localhost:3000/assets/logo-5fa60e416f495e562c56a5087fe696dc.png 404 (Not Found)
What is going on?
I also notice that when I switch to production I also starting getting javascript errors like "JQuery is not found" for jquery tools EVEN THOUGH no problems in development AND I specify in my application.js that jquery should be loaded first before any other javascript files.
The solution is simple (finding it was not).
Simply update your config/production.rb to reflect the following:
config.serve_static_assets = true
Though this is set to false by default, only when you set it to true will you be able to properly run your rails 3.1.x application locally (via webbrick or in my case thin) in the production environment. You'll probably want to set it back to false before you deploy to your actual production server.

twitter gem not working in heroku?

I'm working on a ruby app that updates a twitter account using 'twitter' gem. It's working fine locally (as usual :) ). But when I deploy it on heroku it seems the gem is not properly installed or something lile that as I got the following error:
NameError: uninitialized constant Twitter::OAuth
My code is very simple:
oauth = Twitter::OAuth.new(consumer_token, consumer_secret)
oauth.authorize_from_access(access_token, access_secret)
client = Twitter::Base.new(oauth)
client.update("Updating my status from twitter gem. GREAT!")
Is there a problem with this particular gem ?
Thanks a lot for your help.
Luc
Have you created a .gems file and put twitter in it?
Depending on which heroku 'stack' you are on, you may need to do that instead of a bundler Gemfile. You can change your stack for one that uses bundler by doing this:
heroku stack:migrate bamboo-ree-1.8.7
Which makes bundler available (I think).
That is a common message that usually implies that you have a discrepancy between your local gems and the gems in heroku. If you are not using Bundler yet, you should. You will end un writing a very simple Gemfile that will tell Heroku (or any other entity using your code) which gems and versions you require.
http://gembundler.com/
I would suggest that you should use the heroku addon called 'apigee', ut makes twitter on heroku simple:
http://addons.heroku.com/apigee
I just got a sinatra app talking to Twitter through Heroku/Apigee, my rate limit went from 300 calls per hour to 20,000 calls per hour. Here's a step by step on what to do:
http://geeks.aretotally.in/mind/2011/1/8/increasing-api-limits-on-a-sinatra-twitter-app-with-twitter_.html
I am really a Java developer just playing around with Sinatra but let me know if I can help in anything.
Felipe

Resources