How to rename rails 4 app? - ruby-on-rails-3

rails plugin install git://github.com/get/Rename.git will allow us to rename only rails 3 app
Is there any gem available to rename Rails 4 app.
If not, suggest me the better way to rename.

Since rails 4.1.x, if you want to rename your application, the only two files you need to modify are config/application.rb:
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module YourApplicationName # <-- rename it here
class Application < Rails::Application
...
end
end
and config/initializers/session_store.rb (optional):
# Be sure to restart your server when you modify this file.
Rails.application.config.session_store :cookie_store, key: '_your_application_name_session' # <-- rename the key
For Rails 4.0.x you can use the rename gem and execute the following command:
rails g rename:app_to New-Name
This will update the necessary files for you:
old/ (master) › rails g rename:app_to new
Search and replace module in to...
gsub config.ru
gsub Gemfile
gsub Gemfile.lock
gsub Rakefile
gsub README.md
gsub config/application.rb
gsub config/boot.rb
gsub config/environment.rb
gsub config/environments/development.rb
gsub config/environments/production.rb
gsub config/environments/test.rb
gsub config/initializers/backtrace_silencers.rb
gsub config/initializers/filter_parameter_logging.rb
gsub config/initializers/inflections.rb
gsub config/initializers/load_class_extensions.rb
gsub config/initializers/mime_types.rb
gsub config/initializers/secret_token.rb
gsub config/initializers/session_store.rb
gsub config/initializers/update.rb
gsub config/initializers/wrap_parameters.rb
gsub config/routes.rb
gsub config/initializers/session_store.rb
Renaming references...
Renaming directory...Done!
New application path is '/Users/username/code/new'

Add
gem 'rename' to Gemfile
then
bundle install
After that
rails g rename:app_to name_of_app
And if you are using mongoid then you need to rename the database name in config/mongoid.yml

There are two ways:
1 . Manually (For Rails 4.1.x)
You need to manually find the references to the application name. And you need to change them manually. Here is some common places where it is used:
config/application.rb
config/environment.rb
config/environments/development.rb
config/environments/production.rb
config/environments/test.rb
config/initializers/secret_token.rb
config/initializers/session_store.rb
config/routes.rb
config.ru
app/views/layouts/application.html.erb
Rakefile
2 . Automatic (For Rails 3 and 4.0.X)
Or you can use the rename gem and execute the following command:
rails g rename:app_to New-Name

For Rails 5
Require
config/application.rb change the module name
Optional
config/initializers/session_store.rb (in Rails.application.config.session_store) change the session name
app/views/layouts/application.html.erb You can change the <title>...</title>, if it is not already done

I just used this rename gem in a basic rails 4 app:
https://github.com/morshedalam/rename
This is quite a bit different to get's version.
Easy enough to use:
Add this to Gemfile:
gem 'rename'
And run:
rails g rename:app_to NewName
Seemed to the trick,
It also updated my rubymine .idea project settings :)

In Rails 4.2 just change in application config file
config/application.rb
and config/initializers/session_store.rb (optional):
Rails.application.config.session_store :cookie_store, key: '_your_application_name_session' # <-- rename the key
then restart your server.
That's it!

For rails 5.2
Add gem 'rename' to the gemfile
bundle install
rails g rename:into your_new_app_name

Here is a gem specifically for Rails 4
https://github.com/negativetwelve/rails-rename
(I haven't used it but it seems fine)
The other gems listed here only target Rails 3

In Rails 5.x, doing it manually
using ag (https://github.com/ggreer/the_silver_searcher), there are files that use the default folder name (if generated via rails new .)
three basic files, relative to root of project, need to be updated:
config/cable.yml > channel_prefix:
config/environments/production.rb > # config.active_job.queue_name_prefix
package.json > name
There are sure to be more locations as mentioned previously such as database etc. Hope this helps.

How to Rename a Rails 6.1.3 Application
the "rename" gem doesn’t appear to be tested against Rails 6 at this time according to their documentation so I opted for the manual route.
config/database.yml (rename the 3 databases)
config/application.rb (rename the module)
package.json (rename the package name)
README.md (in case it mentions your old app name)
app/views/layouts/application.html.erb (rename the title)
config/cable.yml (name the Channel_prefix database to the new production database)
Run npm install so that the name attribute you previously updated in package.json is registered.
Run your migrations rails db:migrate
Start your server rails s

For Rails 6.1 Here is what I did:
rename module config/application.rb
run bundle install
and run rails db:migrate.
after that running rails c then Rails.application.class.module_parent.name

Related

How can I get rails to use pg by default?

It's not a huge burden but I would really like to be able to change the default gem-set on my rails apps when I create them so that they're ready for Heroku.
What is the best way to go about doing this?
You can specify the database with -d when running rails new:
Usage:
rails new APP_PATH [options]
Options:
-d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
# Default: sqlite3
Description:
You can specify extra command-line arguments to be used every time
'rails new' runs in the .railsrc configuration file in your home directory.
So for PostgreSQL this is:
rails new myapp -d postgresql
To make this the default put -d postgresql into ~/.railsrc
Another option is to change gem 'sqlite3' to gem 'pg' in your Gemfile as suggested in Getting Started with Rails 3.x on Heroku.

apn_sender gem daemon not running

Im using apn_sender for rails 3 and i have been able to install the gem and get it working just fine by using
rake apn:sender
I have tried to get it started in production mode on a ubuntu box by starting the daemon and it does not seem to work. When i type
script/apn_sender --environment=production --verbose start
I dont see anything. No log present.
when i try to type
script/apn_sender status
It returns with
apn_sender: no instances running
Just trying to understand why it is not running.
i just solved this problem. Try to create a file called 'script' in generators/apn_sender/templates . .
Put this in your script file
# !/usr/bin/env ruby
# Daemons sets pwd to /, so we have to explicitly set RAILS_ROOT
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
require 'rubygems'
require 'apn'
require 'apn/sender_daemon'
APN::SenderDaemon.new(ARGV).daemonize
bash 'rails g apn_sender' in your terminal and will create 'script/apn_server' with same content as above
After that bash this code
./script/apn_server --environment=production --verbose start
it will create log/apn_sender.log . Try running
APN.notify('token',{:alert => '#' , :badge => 1})
or else in rails c to confirm if it works or not , and of course
rake apn:sender
Hope it will help :)
EDIT
You have to install redis and configure

"uninitialized constant Encoding" using rvm, ruby 1.9.2, bundler and passenger

I am at wit's end here and am turning to you all for some help on this f*#$^ encoding issue.
I am running on a private server with root permissions on Dreamhost. Here is a bit about my environment and versions.
$ `which ruby` -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
$ `which bundle` -v
Bundler version 1.0.15
$ `which rails` -v
Rails 3.0.9
Aside from this error, my rails app runs fine without issue. However, when I try to change the encoding a string by using the encode method it:
NoMethodError: undefined method `encode' for "foobar":String
encode should be defined but it is not! Encoding is found if I try in irb:
$ irb
ruby-1.9.2-p180 :001 > Encoding
=> Encoding
ruby-1.9.2-p180 :002 > "foobar".encode('utf-8')
=> "foobar"
But if I try using the rails console through bundle exec, Encoding is not found:
$ bundle exec rails c staging
Loading staging environment (Rails 3.0.9)
ruby-1.9.2-p180 :001 > Encoding
NameError: uninitialized constant Encoding
from /[REDACTED]/shared/bundle/ruby/1.8/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing'
from (irb):1
ruby-1.9.2-p180 :002 > "foobar".encode('utf-8')
NoMethodError: undefined method `encode' for "foobar":String
Obviously the setup is not loading something correctly but I am not sure where to look to figure it out. What am I missing here?
UPDATE 6/19/2011
As Ryan Bigg pointed out, it is curious that the directory path for the gems is 1.8. However, running bundle exec shows that bundler is using the correct ruby and rails versions:
$ bundle exec which ruby
/path/to/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
$ bundle exec `which ruby` -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
$ bundle exec which rails
/path/to/shared/bundle/ruby/1.8/bin/rails
$ bundle exec `which rails` -v
Rails 3.0.9
Clearly something is wonky here… I just don't know what.
UPDATE 6/26/2011
Seamus asked for the $LOAD_PATH…
UPDATE 6/26/2011 (later)
Seamus asked for the Gemfile.lock and the pp ENV… In the ENV output, I found that the GEM_PATH was not correct. In my staging.rb environment file, I have:
GEM_HOME = "/home/[REDACTED]/.rvm/gems/ruby-1.9.2-p180#[REDACTED]"
GEM_PATH = "/home/[REDACTED]/.rvm/gems/ruby-1.9.2-p180#[REDACTED]:/home/[REDACTED]/.rvm/gems/ruby-1.9.2-p180#global"
…which is obviously not being honored. Nowhere else in my code is there a mention of GEM_HOME or GEM_PATH
UPDATE 6/27/2011
Seamus asked for the .bundle/config contents…
UPDATED same idea (that GEM_HOME is messed up), but more suggestions
Your GEM_HOME is messed up, possibly because your PATH is messed up. You could try setting the following environment variable in your shell
$ export PATH=[your current path but with rvm's ruby 1.9 at the front]
Then run
$ bundle install
If that doesn't work, try also setting this in your shell
$ export GEM_HOME=[your ruby 1.9 gem home]
and then re-run
$ bundle install
New ideas from this answer: Using RVM, bundler does not install in proper gemset when gems are installed in a different ruby version

RVM & Unicorn deploy

My RVM is installed as root.
When I'm trying to start unicorn socket, it prints
user#9001-3:~$ /etc/init.d/unicorn start
Starting myapp app: /usr/bin/env: ruby: No such file or directory
unicorn.
But if I type
user#9001-3:~$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
/usr/local/rvm/gems/ruby-1.9.2-p180/bin/unicorn path exists.
My unicorn config: https://gist.github.com/1010519
/etc/init.d/unicorn doesn't know where to find Ruby because it's managed via RVM. Normally, your .bashrc or similar file is executed and sets up the environment; this doesn't happen in init scripts (or likely anything else executed by root).
The solution is to use wrappers. For example, to create a binary called system_ruby that loads up RVM's 1.9.2p180 environment and then executes ruby, execute the following:
rvm wrapper ruby-1.9.2-p180 system ruby
For more information and more details, check out this answer of mine, which addresses a similar problem.
Symlink also works,
which ruby<your version>
ln-s /ruby/path/ruby<your version> /ruby/path/ruby
Type :
which ruby (show the ruby bin path) then type this : ln -s (change_to_ruby_path) /usr/bin/env/ruby (construct the correct access for your system)
I had the same problem and this for me
rvm --default use <version>

Resque web interface loading error

I have installed Resque in Rails 3 using this tutorial.
The problem is when I'm trying to use the Resque web interface. When I go to {localhost}/resque/ , the browser is getting redirected to {localhost}/resque/resque/overview/true/false which essentially does not exist.
However {localhost}/resque/overview seems to open up the correct interface, although has broken links. (Like clicking on stats again redirects me to {localhost}/resque/resque/stats/resque/true/false, which is again non-existant)
Here is my config.ru file:
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
require 'resque/server'
require 'logger'
# Set the AUTH env variable to your basic auth password to protect Resque.
AUTH_PASSWORD = 'secret'
if AUTH_PASSWORD
Resque::Server.use Rack::Auth::Basic do |username, password|
password == AUTH_PASSWORD
end
end
run Rack::URLMap.new \
"/" => Marina::Application,
"/resque" => Resque::Server.new
It seems that it's a problem with Sinatra version 1.2.0. Using Sinatra 1.1.3 works fine. Details on this Resque open issue: https://github.com/defunkt/resque/issues#issue/221
From the issue description:
When I go to "/resque" route it
redirects to
"/resque/resque/overview/true/false"
and fail with 404 Sinatra error page.
Add sinatra 1.1.3 to Gemfile, run
"bundle update sinatra" and voila:
http://cl.ly/460d0C0x2N1W2D333j1f
As I'm new to Ruby and don't know yet what is a Gemfile :), I forced the installation of Sinatra 1.1.3 and it worked like a charm:
$ gem uninstall sinatra
$ gem install sinatra -v 1.1.3
Regards,
Deluan.