Rails Heroku app push and see changes - ruby-on-rails

I would like to ask a question about heroku and rails. As I am kind of new to rails I want to know how it works with Heroku. I have an app and would like to push it to heroku.
I know that, rails takes all js/css files and compress when you are in production mode. My problem is, when I change js or css locally and push back to same heroku app, how rails handles these changes. It would be so stupid to destroy heroku app and push again.

Everytime you make changes to your application locally you should run "bundle exec rake assets:precompile RAILS_ENV=production". This will compile your assets in the public folder and then you should commit them to git . Then upon running "git push heroku master" you will see your new assets on the deployed app once it is reloaded.
As far as destroying the app. goes, when pushing changes it is only restarted. Your database and all else are kept in tact.

Related

Rails 6 deployed on Heroku won't update Stylesheets

I built a Rails 6 app and deployed it to Heroku. But any changes I make to the stylesheet are not reflected. All the Heroku documentation and SO questions/answers appear to no longer be relevant to the current Rails setup in this regard. I could precompile the assets before pushing to heroku but I'd prefer not to. And actually I did find a "solution" but it feels more like a hack than a real solution. If I open config/initializers/assets.rb and change the statement:
Rails.application.config.assets.version = '1.0'
to
Rails.application.config.assets.version = '1.1'
then it will update the assets. But that means if I am experimenting with the look of the site I would be changing the version all the time. I mean if that's they way it's supposed to work I'll live with it, but it doesn't seem right. Anyone know a way to get Heroku to just update it on every push?
You've to compile the assets from the heroku end(i.e. in your server on Heroku), so after pushing your code to Heroku, run:
$ heroku run rake assets:precompile
# If above doesn't work
$ heroku run RAILS_ENV=production rake assets:precompile
Also, it's a good practice to add public/assets(or whatever folder that precompiles to) folder to your .gitignore file, so incase if you precompile assets in your local environment this will not mess up with your production env when you push to Heroku. But everytime you change some CSS and push to heroku, you'll need to precomile assets on Heroku end from the above command.

Heroku Not Updating

I have been learning Ruby on Rails with heroku from an online tutorial. Everything has been working fine. However, my latest attempt to update my heroku site has failed.
i've run:
"git push heroku master"
and
"heroku run rake db:migrate"
however, my local changes are not updating.
note: the only changes that don't seem to be taking affect are database updates. for instance, i can update the home file and see its changes on heroku, but i can't login to a new user account with devise.

Issue with heroku

I have gone through the proper protocol with Heroku, installed the gem puma, created a Procfile, and have successfully implemented the git push heroku master command. But when I opt to initiate Heroku open, the website will not display my app. I ran Heroku logs --tail, and the error comes up that the app crashed. When I ran Heroku run rake db:migrate, this message came up:
heroku run rake db:migrate
Running rake db:migrate on stormy-tor-8615... up, run.9976
ActiveRecord::SchemaMigration Load (1.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
Is this indicative that my app's models were successfully migrated? If not, how can I properly troubleshoot this issue?
Firstly I will suggest you check if you are still on a feature branch locally. if you are, you may want to push that branch instead. you can do that by typing git push heroku master:(your branch name)
I just resolved the problems with my app, it turned out that the spec file was duplicated in the app directory, and once I removed it, I then directed my attention to the config/secrets.yml, where the residing issue was how I initially setup the secret_key_base ENV hash. There was a slight error in the original entry, which in retrospect, broke the app when I attempted to push it to Heroku. After I correctly reconfigured the ENV hash, the app was able to be accessed via Heroku. And, then I was able to manually input the Facebook App id and APP secret key via the terminal.

Heroku + Rails Workflow

I have deployed my app on Heroku but am running into issues that I don't have when running the app locally. Because of this, I'm making a lot of tweaks to my code, and I'm finding that my workflow for pushing new code to Heroku takes a long amount of time (about 5 min each time), so I'm wondering if I'm doing something wrong. Before I push my code, I precompile my assets using
rake assets:precompile
This takes a few minutes to do. Then I do a commit and push my code to Heroku using:
git push heroku master
This also takes a few minutes to do. Do I need to precompile every time I push code to Heroku? Is there any way of making this process faster?
No - The Heroku Ruby buildpack will run assets:precompile for you if you haven't already.
https://devcenter.heroku.com/articles/rails-asset-pipeline

Deploying Heroku app--updating my code?

This is a basic, stupid question, but I configured my Rails app to deploy on Heroku, and I'm able to open the application from my Heroku account, etc. But when I want to change my code, do I need to re-deploy the whole application? I tried just committing/pushing to heroku master, but I get the error "fatal: remote end hung up unexpectedly." What should I do instead?
Also: am I supposed to run db:migrate BEFORE deploying/pushing?
There is nothing stupid about a basic question, as everyone has to start somewhere.
The basic process with deploying a Rails app to Heroku is to:
Make changes
Add and Commit your changes ($ git add files_changed.rb & $ git commit -m "make changes")
Push your changes to Heroku ($ git push heroku master)
This then pushes your code to the remote Heroku repository and redeploys your Rails application. If you have made any database migrations, you need to run:
$ heroku run rake db:migrate
This runs db:migrate on your heroku app - see how that works? :)
Running rake db:migrate locally simply migrates your local development database.

Resources