Ruby on rails project deploy to server - ruby-on-rails

I have a ruby on rails project. It runs successfully on my PC with command "rails s". So I decided to deploy it to AWS using Capistrano. Server side, I am using Puma + Nginx + mysql stack. (I am following this guide: https://www.sitepoint.com/deploy-your-rails-app-to-aws/)
I got error when I run "cap production deploy":
Tasks: TOP => deploy:assets:precompile
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deploy2#111.21.5.197: rake exit status: 1
rake stdout: rake aborted!
Sass::SyntaxError: Invalid CSS after "...e bootstrap.min": expected "{", was ""
(sass):6648
I found out it was the file app/assets/stylesheets/application.css causes the error. In this file, I have only one line:
*= require bootstrap.min
I think it is correct. Because the app can run on my PC.
If I remove this line, there will be no error when I run "cap production deploy". The app can deploy to the server and run on the server. But no CSS for all the web pages. I am basically new to ruby on rails. So I don't know the details after all these files. Does anyone can suggest what should I do in order to make my app deploy to the server successfully?

Rename your stylesheet to application.scss (note the scss extension) and make sure it contains this line:
//= require bootstrap.min

Related

rails assets precompile error with a js with variable definitions with a -. works on one computer and in other not

I'm running RAILS_ENV=production bundle exec rake assets:precompile and getting this error
...somefile.js
ExecJS::ProgramError: Unexpected token: operator (-) (line: 3, col: 9, pos: 11)
This is the content of that line:
var color-green="#27cebc";
I guess the problem is because the variable name includes a -. However using the same ruby version on local computer with same command, it's able to process correctly without the error:
On my local computer:
RAILS_ENV=production bundle exec rake assets:precompile`
And it was able to process the offending file without problems, and generated this file:
public/assets/js/some=file-68c9a5f2e1f2216c5d3d2b9fcd7741155113425f7f46f18187ad5b98e1a11092.js
$ ruby -v
ruby 2.2.1p85
$ gem list | grep js
execjs (2.5.2)
I tried commenting the line out and it process all the files succesfully, but I dont understand why on local it works with that line, and in the server doesnt.
The only reason is assets not compile in development mode. but when you start in production mode its need to compile first.
you can see difference between development.rb and production.rb in environment folder.
you can explore more here.
config.assets.compile=true in Rails production, why not?
You were able to use it locally because you weren't doing the precompilation/preprocessing locally.
However, I doubt if it really worked locally as JS would have thrown an exception of Unexpected token -, because the interpretation of the line is color minus green, as you cannot use - in the name of a variable

LoadError for rails 2 script

I manage a server running an old rails 2 app (being upgraded to rails 4 soon) and there's a script giving an error that running the same code from the console does not. It outputs this when I run the script:
rails#net:/c$ RAILS_ENV=production script/runner stc_cron.rb
/current/vendor/rails/railties/lib/commands/runner.rb:45: /current/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:249:in `load_missing_constant': Expected /current/vendor/other_extensions/stc/app/models/contact.rb to define Contact (LoadError)
but the exact same code run in the rails console is fine and /current/vendor/other_extensions/stc/app/models/contact.rb does define Contact and has no errors
here's the code from the script:
#!/usr/local/bin/ruby
ENV['RAILS_ENV'] = ARGV[0] || 'production'
require 'config/boot'
Extension.load_all
require 'lib/satacard'
stc=SaTaCard.new
stc.get_and_process_new_stc
stc.get_and_process_new_contacts
why would it run fine in the console but fail in the script?
It looks like you are not loading the Rails environment. Load it after config/boot:
require 'config/environment'

Capistrano v3 and Rails migration, precompile and bundle issue

I am trying to deploy an app on a DigitalOcean prebuilt Rails app (unicorn, nginx).
Everything work fine with the standard capistrano v3 recipy, but when i add the following modules to perform migration, bundle install and precompile assets:
require 'capistrano/bundler'
require 'capistrano/rails/migrations'
require 'capistrano/rails/assets'
I get a
DEBUG [4f5bfce9] Command: cd /home/rails/releases/20140307184517 && ( RAILS_ENV=production bundle exec rake assets:precompile )
DEBUG [4f5bfce9] bash: /usr/local/bin/bundle: /usr/bin/ruby1.8: bad interpreter: No such file or directory
DEBUG [4f5bfce9]
which is where i am totally stuck now :S
Looks like the copy of bundler that is being referenced is trying to use ruby 1.8 that does not exist.
Can you check the contents of /user/local/bin/bundle?

Deploying Rails 4 with ricn/rika gem on Heroku - precompile error

I'm running a Rails application using the Rika gem (JRuby wrapper for Apache Tika). It runs fine locally. In trying to push it to Heroku, it gets a ways into the deployment until I hit the asset precompile:
...
-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
No such file to load -- rika
followed by a long string of /tmp/build_8a51... errors.
Precompile works fine on the local machine.
If I try to install the gem via 'heroku run' I get:
$ heroku run gem install rika
Running gem install rika attached to terminal... up, run.8601
ERROR: While executing gem ... (ArgumentError) malformed format string - %)
Any suggestions?
Thanks
Found the problem.
I needed to add the ruby version spec line to the Gemfile. It wasn't necessary on the local machine because I set the version externally. Heroku needs it though.

ROR code is not being deployed on linode with strange error

I have successfully installed and configured apache with passenger for deploying a rails application. I installed the 'mysql' and 'rails' gems successfully, but when I run any rake commands like
rake db:create
to create the database, I get this error
Illegal instruction
Any idea why?

Resources