I am newbie with Heroku and trying to upload a static website to Heroku. Here is what I did with this one.
First, I made a static website named Y , and when I ran localhost:3000, it ran very ok.
Then I followed suggestions from internet, I changed my gemfile
gem 'sqlite3'
to
group :development do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
and, change my routes.rb file like this
Rails.application.routes.draw do
get 'home/index'
root 'home#index'
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
end
But when I tried to run heroku open , it still give me this error
Sorry for my newbie's question, but I am stucking with this one and very confusing. Could you please give me some ideas? Thank you very much.
Check your config/database.yml
You are using pg gem in production but your database.yml file is configured for sqlite3.
It's better to configure your app to use pg on both production and development as well.
You should change your gem file to use gem pg in development
Run bundle install
And then reconfigure your database.yml to use the pg database.
Then run
Rails db:create
Rails db:migrate
And dont forget to add our enviroment variables to heroku so that it can use the database.
Related
I have about 3 apps on a Windows Server 2012 and all of them are different versions of rails. So far, I can run locally the app with the latest version of rails, but not the other two, which were deployed from Heroku. I wanted to make changes locally before I push them to Heroku but no luck. Is there any reference to that or is this even possible? thanks a lot!
Your problem is that you are trying to use sqlite with Heroku. Heroku requires using 'postgres' as the database
change the gemfile to the following
group :development do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
And then change your database.yml file to this
adapter: postgresql
My Active Admin Layout Not Comes in Production Environment.
I added in Gemfile
gem 'activeadmin', github: 'gregbell/active_admin'
See My Active Admin Page
Help me Please.
Thanks In Advance
Im using Rails 4 and after running the server in RAILS_ENV=production i would get the same layout as you did, although it works in the development environment. after searching in the web for different answers that one that work for me was the next. Heroku does NOT compile files under assets pipelines in Rails 4 i find the answer here.
add rails_12factor to your gemfile
gem 'rails_12factor', group: :production
then
bundle install
and then restart your server
i did some modifications to config/application.rb file but it never worked for me (somthing to do with precompile assets) therefor i dont think it's necessary.
hope it helps
I will try my best to explain my issue.
I have a SQLite3 database file of about 50,000 records that I compiled and use in my app. This database is read only and is only used to query and pull data from. I created a model for it in rails and it looks like this.
class Locations < ActiveRecord::Base
establish_connection(
:adapter => 'sqlite3',
:database => 'db/locs.sqlite3'
)
set_table_name "Locations"
end
Everything works great on the development end, but fails when I deploy to Heroku. I'm assuming the issue is that Heroku runs on Postrgres but I need this database to be separate from the main production database and I don't need something fancy. All I need is for the app to query some records from this file.
Is there a solution out there? Thanks
Allowing SQLite3 read only can be enabled by following the steps from this git repo.
https://github.com/yotsumoto/heroku-buildpack-ruby-with-sqlite3
After running:
$ heroku config:set BUILDPACK_URL=https://github.com/yotsumoto/heroku-buildpack-ruby-with-sqlite3
I was able to git push heroku master with gem 'sqlite3' still in the Gemfile.
I'm really not understanding your question but I'm assuming you want to use sq in dev & testing but want to use postrgres in product, correct? If so, the code below should help. Switching from sqlite to pg is rather seamless so you shouldn't have a problem doing so.
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg', '0.12.2'
end
The simple answer to your question is it's not possible to do what you're trying to do. Heroku don't have necessary prerequisites installed to even let you install the sqlite gem.
I have run 'heroku db:push' to download heroku db updates, it show me error:
taps load error: no such file to load --sqlite3
you may need to install or update the taps gem to use db commands.
on most systems this will be: sudo gem install taps
I have installed heroku 2.25.0, taps 0.3.24 and I changed the Gemfile replacing gem sqlite3 with:
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
I think it's a problem of compatibility database between sqlite e postgresql.
is it possible? Or what can be ?
First, make sure you've got your gems all up to date by running bundle install. It won't hurt if everything's fine so you may as well make sure.
After that, you should be able to use db:pull to pull a copy to your local machine using the snippet that follows:
bundle exec heroku db:pull sqlite://local.db --app my_app
If this doesn't work for some reason, you can just change your Gemfile while pulling the database down -- and then you can change it back if you want to.
group :development, :test do
gem 'sqlite3'
# add this next line and run 'bundle install' until you get db:pull to work
gem 'pg'
end
group :production do
gem 'pg'
end
(I believe this will work, though I personally haven't tried it. Please respond if there's an issue.)
Finally, there are some issues pulling and pushing databases if you're running ruby 1.9.3 on your local machine -- but it's only if you're doing a db:push. If you have problems with that here's a link to the solution.
When you run the heroku command, it runs locally on your development machine. So the development group of your Gemfile is used:
group :development, :test do
gem 'sqlite3'
end
Since it contains sqlite3, you need the sqlite3 gem to be installed on your development machine. Have you run bundle install to install this gem locally? And you may need to run the heroku command within a bundle exec call to make sure the gems are loaded:
bundle exec heroku db:pull.
Finally, if you want to download Heroku DB, you should use db:pull, not db:push.
I'm new to Heroku. I tried pushing a simple test Rails 3.1.1 app to Heroku. The only changes that I made to it from the "new" Rails app template was to create a Home controller and point the root to home#index. I also ran
rails g scaffold Mark type:string start_time:datetime end_time:datetime subject:string measure:float special_event:boolean flag:boolean in_progress:boolean
so that I could run a database migration and test to make sure all showed up properly. The final change that I made was to the Gemfile, which now looks like this:
source 'http://rubygems.org'
gem 'rails', '3.1.1'
group :development do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
group :assets do
gem 'sass-rails', '~> 3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
I followed the Heroku tutorial for this. The push worked, there were no errors reported. I ran heroku rake db:migrate heroku addons:add logging. I also deleted public/index.html from the app. When I run the app locally with rails server, it works fine. I also can manually navigate to the "marks" index, per the scaffold.
When I run heroku open, all I get is the standard We're sorry, but something went wrong. Rails page. heroku logs shows me nothing at all.
What am I doing wrong here? This is about as simple as test cases get, yet I can't get it to work after fiddling with it for hours, creating new apps, deleting this app and trying again, trying to deploy another app, etc.
The problem here is that Rails 3.1 asset pipeline doesn't work 'out of the box' on Bamboo-mri-1.9.2 which is the default when you do heroku create.
The solution is to do heroku create --stack cedar and then push - all will be fine then :)
Try doing this just to see if this works:
rails new stackoverflow
cd stackoverflow/
git init
git add .
git commit -m 'all'
git remote add origin git#github.com:noahc/stackoverflow.git #you'll need to change this
git push origin master
heroku create
git push heroku master
heroku open
If that doesn't work, then it is something to do with your local machine. I just ran through this and it works on my end. See: http://gentle-dawn-1050.heroku.com. If this doesn't fail, I'd try making the changes to the GemFile and see if you can get it to fail that way.
I had the same problem. Looks like you got to the bottom of your issue, but for future problem-havers I want to point out that it could be a discrepancy between the database you use for your local app and the one behind the live app. In my case, my local database was populated, and my Heroku site was empty, since l I didn't properly migrate.
This problem only became apparent when I ran "rake db:reset" in the terminal, (to clear all the data in my local app's database), after which I was able to easily find the bugs in my code.
Conclusion: if the information in your database is negligible, I would suggest clearing it and troubleshooting from there, because it could be that the site you've deployed just doesn't have data yet, and maybe your code doesn't properly handle that kind of exception.......