Bootstrap and Rails issue with Heroku Deployment - ruby-on-rails

Im making a Ruby on Rails app. I've included the twitter-bootstrap rails gem. Having tested the app locally, I've attempted numerous times to deploy to Heroku. I first encountered this 500 error:
ActionView::Template::Error (images/apple-touch-icon-144x144-precomposed.png isn't precompiled)
I solved this initial problem, by adding this line to the config/environment/production.rb file.
config.assets.compile = true
Now, I'm trying to push my rails app to Heroku again but when I push to Heroku I'm getting this 500 error again. I have no idea how to solve this one:
ActionView::Template::Error (undefined local variable or method `bootstrap_flash' for#<#
77: </div><!--/span-->
79: <%= bootstrap_flash %>
78: <div class="span9">
80: <%= yield %>
app/views/layouts/application.html.erb:79:in `_app_views_layouts_application_html_erb___2619453860724409461_34912060'
81: </div>
82: </div>
Any help would be greatly appreciated!
This is my Gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.13'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'pg'
gem 'devise'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
gem "therubyracer"
gem "less-rails"
gem 'twitter-bootstrap-rails', :git => 'http://github.com/seyhunak/twitter-bootstrap-rails.git'
end
gem 'jquery-rails'
I've tried rake assets:precompile and then upload to Heroku but still, no luck.

You seems to be having this previously reported issue. Try adding the following gem:
gem 'bootstrap_helper'
You can also add this File, as one of your helpers. That's what fixed for most of the folks on that thread.

Related

Getting Google Analytics up in Rails 3 App

I've tried all the methods outlined Here for getting google analytics up and running on my rails app.
I think that google is talking to my app because when I inspect the elements and look at the network I see the .js file.
I thought I might need to just sit and wait but this didn't work. I've now tried several ways to do this and nothing is working.
gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.11'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
# For google analytics
gem 'google-analytics-rails', '1.0.0'
gem 'activeadmin'
gem 'pg'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
group :development do
gem 'pry'
end
gem 'rails_12factor'
gem 'delayed_job_active_record'
gem 'unicorn'
I have this line in my head tag at the bottom.
<%= analytics_init if Rails.env.production? %>
I thought this was the problem so I removed the if statement but that seemed like a bad idea as it would allow google to track any environment.It still didn't work after this...
What am I missing? I've never had this problem with analytics before. Any suggestions?
My guess is that you forgot to replace the placeholder within the analytics.js.coffee file.
#analyticsId: ->
# your google analytics ID(s) here...
'UA-XXXXXXX-XX'

RoR app: Problems deploying app to heroku

I created an heroku app recently for an existing rails app I've been working on. I only have one html file that I'd like to see displayed on my browser. This file gets news stories from my database (sqlite3-- should technically work from a development standpoint. I've gotten it to work with the railstutorial, where I didn't configure postgres at all), along with their corresponding images, and spits them to the page. This works perfectly on localhost, but when I deploy using 'heroku open', all I see is a blank white page with the heading tag that I added at the very top of the page: 'Top stories from BBC'. It's as if the app doesn't read the eRB tags at all. Here's the code for my index view html.erb file:
<h1> Top stories from BBC <h1>
<% #stories.each do |story| %>
<% if story.image.nil? %>
<% # do nothing %>
<% else %>
<div>
<h3><%= story.name %></h3>
<p><%= story.summary %></p>
<a href = "<%= story.url %>" >
<img src="<%= story.image %>" />
</a>
</div>
<% end %>
<% end %>
Here's my gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.8'
gem 'feedjira'
gem 'mechanize'
gem 'nokogiri'
# Use sqlite3 as the database for Active Record
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.2'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
I keep using heroku and git commands such as :
git push
git push heroku
heroku run rake db:migrate
rake assets:precompile
git add . /git commit -m/etc.
git push heroku master
Even after trying the above in multiple different combinations, nothing seems to work. I would appreciate any feedback you guys can offer as to how I can get my index page to render properly over Heroku. It works perfectly over local host.
Thanks, your help will be greatly appreciated!
You've pushed your code to Heroku, but your Heroku database is empty. If you have data in your local database you want on Heroku just push!
heroku pg:push mylocaldb HEROKU_POSTGRESQL_MAGENTA --app sushi
Where:
mylocaldb is the name of your local databases
HEROKU_POSTGRESQL_MAGENTA is the name of your heroku database (find it from heroku pg:info -a myapp)
IMPORTANT: Heroku uses postgres, so you should be using postgres locally as well. Many of the commands stated here require you to have postgres installed on your machine.
Be sure to read through the very useful help pages Heroku has: https://devcenter.heroku.com/articles/heroku-postgresql#pg-push-and-pg-pull

Rails LoadError when trying to start server

I'm following SaaS from edX and I'm trying to run my rails server that I created using
rails s
and it keeps throwing a load error for
gem/ruby-1.9.3-p448/gems/ruby-debug-base19-0.11.25/lib/ruby_debug.so:
undefined symbol: ruby_current_thread
I'm not quite sure what I can do to fix this, or what other info would be required to help me solve this. I'm sorry for such a vague post but ruby on rails is rather new to me and I'm not sure why its throwing this
ive tried
gem install rails
and i get a permissions error
*Edit 1
Gemfile The debug19 is what i was told to put in per my instructions from edX 169.1
source 'https://rubygems.org'
gem 'rails', '3.2.14'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
gem 'haml'
# To use debugger
# gem 'debugger'
group :development ,:test do
gem 'ruby-debug19' , :require => 'ruby-debug'
end
I don't know enough about your environment to give an exact answer, but you can try removing ruby-debug-base19 and ruby-debug from your Gemfile. You can also see if it's being installed by another gem by looking for references to them in your Gemfile.lock. If they are dependencies, remove the gems they depend on as well.

Unicorn triggers mongoid error during assets precompile

I have a rails app using Mongoid 3 running on Heroku. I've just updated it to use Unicorn. When I try to deploy it to Heroku I get the following error :
Running: rake assets:precompile
rake aborted!
undefined method `match' for nil:NilClass
/tmp/build_3nnbzpfmnjpns/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.21/lib/mongoid/sessions/mongo_uri.rb:49:in `initialize'
The full stacktrace can be found at http://pastebin.com/8YcJHEmS
But if I remove Unicorn from my Gemfile, the assets compilation succeeds. Looking into the Mongoid code, I can see that the error happens when the mongoid.yml file is getting parsed, but I can't figure out why Unicorn would cause that to fail.
My mongoid.yml file looks like this :
production:
sessions:
default:
uri: <%= ENV['MONGOHQ_URL'] %>
options:
skip_version_check: true
safe: true
And my Gemfile :
source 'https://rubygems.org'
ruby '1.9.3'
gem 'rails', '3.2.11'
gem 'thin'
group :assets do
gem 'sass-rails', '~> 3.2'
gem 'coffee-rails', '~> 3.2'
gem 'uglifier', '>= 1.0.3'
gem "twitter-bootstrap-rails", '>=2.1.8'
gem "bootstrap_form"
end
gem "jquery-rails"
gem 'jquery-ui-rails', "3.0.1"
gem 'newrelic_rpm'
gem "httparty"
gem "resque"
gem "resque-loner"
gem "unicorn", "4.4.0"
gem "mongoid", "~> 3.0.0"
gem "mongo", "~> 1.7.0"
gem "bson", "~> 1.7"
gem "bson_ext", "~> 1.7"
gem 'less-rails', "~> 2.2"
gem 'therubyracer', '>= 0.11.1'
gem 'libv8', '~> 3.11.8'
gem 'devise', '~> 2.1.2'
gem 'devise_invitable', '~> 1.0.0'
gem 'bootstrap_form'
gem 'font-awesome-rails'
gem 'omniauth'
gem 'omniauth-facebook'
gem 'kaminari'
gem 'mongoid_search'
Would you have any idea what's causing this ?
As I recently had this problem with Rails 4.0 and config.assets.initialize_on_precompile = false no longer has any effect with Rails 4.0 I spoke with Heroku support and was told to use this labs feature:
heroku labs:enable user-env-compile
I wasn't able to get an answer as to why the user environment is necessary only with Unicorn but it seems to be a Unicorn specific problem of some sort or Thin does something that prevents the entire app from booting.
The whole thing seems odd to me and smells of a problem with the way assets are pre-compiled.
Rails 3:
Try to turn off app initialization when pre-compiling assets:
# config/application.rb
config.assets.initialize_on_precompile = false
The line should already be there commented out.

More informative SASS error messages?

How can I get more informative error messages from SASS? It's a Rails 3.1 app that works fine in development mode, in production all I get is:
Sass::SyntaxError in Pages#home
Showing C:/documents/projects/aaa_0003/implementation/ror/aaa0003/app/views/layouts/application.html.erb where line #7 raised:
0.3 is not a color for `alpha'
(in C:/documents/projects/aaa_0003/implementation/ror/aaa0003/app/assets/stylesheets/application.css)
Extracted source (around line #7):
4: <head>
5: <title><%= title %></title>
6: <%= csrf_meta_tag %>
7: <%= stylesheet_link_tag "application" %>
8: <%= javascript_include_tag "application" %>
Gem file is:
source 'http://rubygems.org'
gem 'rails', '3.1.3'
gem 'pg', '0.11.0'
gem 'gravatar_image_tag', '1.0.0.pre2'
gem 'will_paginate'
gem 'rake'
gem "jquery-rails"
gem "nested_form"
gem 'acts-as-taggable-on'
# Gems used only for assets and not required
# in production environments by default.
gem 'sass-rails', '~> 3.1.5'
group :assets do
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
group :development do
gem 'rspec-rails', '2.5.0'
gem 'annotate', '2.4.0'
gem 'faker', '0.3.1' ## for creating loads of random users to test the site with.
end
group :production do
gem 'therubyracer-heroku'
end
Thanks.
So I ended up just manually searching through my .css.scss files and found the offending line, which indeed was trying to use a deprecated / broken css styling rule to set opacity to 0.3. All working now.

Resources