Ruby on Rails site transfer to c9


#1

I’m literally brand new to Ruby on Rails. I’m working through the ROR tutorial because a company just gave me (gave it to my company, actually) their Ruby on Rails site.

I have it unzipped in a workspace, but I have no idea how to get it live, setup the database, install gems, etc etc.

Is there some resource for moving a website, or setting up a site that’s already developed somewhere? Can someone push me in the right direction?

Thanks

-Matt


#2

So a follow up, I was able to install rails (4.1.9) and I installed a couple of gems imagemagick and rmagick.

Then I ran bundle install and everything seemed to work.

Next is the database. I ran rake db:migrate and I get the error:

Mysql2::Error: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

Now I’m stuck again.

Any ideas?


#3

Hey @madmin :smiley:,

Glad to hear you’re making progress. Have you seen the C9 docs yet on setting up MySQL in a Cloud9 Workspace:

:bookmark: :cat2:


#4

OK, so I mildly feel like an idiot, but apparently installing MySQL does not actually start MySQL. Thanks @mikeumus

$ mysql-ctl start

Then I realized that $ rake db:migrate actually needed a db to migrate to so:

$ rake db:create db:migrate

OK, so I think that should be everything, but…

when I run $ rails server -b $IP -p $PORT I get:

=> Booting Puma
=> Rails 4.1.9 application starting in development on http://0.0.0.0:8080
=> Run rails server -h for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (–binding option)
=> Ctrl-C to shutdown server
Puma 2.14.0 starting…

  • Min threads: 0, max threads: 16
  • Environment: development
  • Listening on tcp://0.0.0.0:8080

Started GET “/” for MY.IP.ADD.RESS at 2015-12-22 23:43:48 +0000
ActiveRecord::SchemaMigration Load (0.2ms) SELECT schema_migrations.* FROM schema_migrations
Processing by Refinery::PagesController#home as HTML
Parameters: {“locale”=>:en}
Refinery::Page Load (2.2ms) SELECT refinery_pages.* FROM refinery_pages WHERE refinery_pages.link_url = ‘/’ ORDER BY refinery_pages.id ASC LIMIT 1
Refinery::Page Load (0.2ms) SELECT refinery_pages.* FROM refinery_pages WHERE refinery_pages.menu_match = ‘^/404$’ ORDER BY refinery_pages.id ASC LIMIT 1
Rendered public/404.html (8.2ms)
Filter chain halted as :find_page rendered or redirected
Completed 404 Not Found in 153ms (Views: 70.6ms | ActiveRecord: 6.6ms)

Started GET “/” for MY.IP.ADD.RESS at 2015-12-22 23:43:53 +0000
Processing by Refinery::PagesController#home as HTML
Parameters: {“locale”=>:en}
Refinery::Page Load (0.2ms) SELECT refinery_pages.* FROM refinery_pages WHERE refinery_pages.link_url = ‘/’ ORDER BY refinery_pages.id ASC LIMIT 1
Refinery::Page Load (0.1ms) SELECT refinery_pages.* FROM refinery_pages WHERE refinery_pages.menu_match = ‘^/404$’ ORDER BY refinery_pages.id ASC LIMIT 1
Rendered public/404.html (0.1ms)
Filter chain halted as :find_page rendered or redirected
Completed 404 Not Found in 48ms (Views: 32.5ms | ActiveRecord: 0.3ms)

Started GET “/” for MY.IP.ADD.RESS at 2015-12-22 23:44:52 +0000
Processing by Refinery::PagesController#home as HTML
Parameters: {“locale”=>:en}
Refinery::Page Load (0.1ms) SELECT refinery_pages.* FROM refinery_pages WHERE refinery_pages.link_url = ‘/’ ORDER BY refinery_pages.id ASC LIMIT 1
Refinery::Page Load (0.1ms) SELECT refinery_pages.* FROM refinery_pages WHERE refinery_pages.menu_match = ‘^/404$’ ORDER BY refinery_pages.id ASC LIMIT 1
Rendered public/404.html (0.0ms)
Filter chain halted as :find_page rendered or redirected
Completed 404 Not Found in 33ms (Views: 29.2ms | ActiveRecord: 0.3ms)

And of course - The page you were looking for doesn’t exist.

I’m getting there, I think…

Thanks for the help


#5

Do you get that error message right after starting the server or after starting the server and going to the root path of your application?

Do you get any error message if you run the rails console?

rails console


#6

No errors starting rails console.

Starting rails server gets the error after a few minutes


#7

Glad you’re making progress @madmin :smile:,

Pardon I should’ve included these docs in my initial reply as well, just form completeness even though it looks like you may have already seen this doc too:

:book: :monkey:


#8

I did see this, and thank you @mikeumus

I’m wondering, what happens when there is no homepage the routes file? It looks like I’m simply getting a 404 error


#9

@madmin

Not sure if should be asking this, since you received a project that should supposedly work.

It is strange that you are getting 404 error just by running the server.

Can you post your config/routes.rb file and post the list of directory and check that the root path points to a valid existing view?


#10

@BigChief45

Yes, sure. I think it might have something to do with production, development and test folders. Which I don’t quite understand yet.

routes.rb

Rails.application.routes.draw do
mount ActiveAdminAssociations::Engine, :at => ‘/’

get ‘checkout/new’

get 'checkout/create’
post ‘checkout/create’

get ‘checkout/express_checkout’, as: ‘express_checkout’

get 'carts/show’
get ‘order_products/:id/preview’ ,to: ‘order_products#preview’, as: 'preview’
get 'customer/terms’
get ‘customer/:id/profile_preview’, to: ‘customer#profile_preview’, as: 'profile_preview’
get ‘customer/giftcard_preview’, to: ‘customer#giftcard_preview’, as: 'giftcard_preview’
get 'customer/passwordreset’
get ‘order_products/your_orders’,to:‘order_products#your_orders’,as:'your_orders’
get ‘order_products/:id/renew’, to: ‘order_products#renew’, as: 'renew’
get ‘order_products/welcome’, to: ‘order_products#welcome’, as: 'welcome’
get ‘order_products/congratulations’, to: ‘order_products#congratulations’, as: 'congratulations’
get 'customer/dashboard’
get 'order_products/upload’
get 'customer/pdf_preview’
get ‘order_products/:id/edit_processed_order’, to: ‘order_products#edit_processed_order’, as: 'edit_processed_order’
get ‘order_products/create_zip’
#namespace :customer do
#get ‘order/new’

end

get ‘customer/new_subscription’

ActiveAdmin.routes(self)
devise_for :customers, controllers: {sessions: ‘customer/sessions’, registrations: ‘customer/registrations’,passwords: ‘customer/passwords’}
devise_scope :customer do
delete ‘delete_customer_registration’,to: ‘customer/registrations#destroy’,as: 'delete_customer_registration’
end

resources :customer do

collection do

get ‘edit’

post ‘update’

end

end

resources :products, only: [:index]
resources :order_products do
collection { post :import; delete :destroy_multiple }
end
#,only: [:create,:update,:destroy]
resources :order
resource :cart, only: [:show]

resources :checkout, :new => {:express_checkout =>:get} do

collection do

post ‘create’

end

end

This line mounts Refinery’s routes at the root of your application.

This means, any requests to the root URL of your application will go to Refinery::PagesController#home.

If you would like to change where this extension is mounted, simply change the

configuration option mounted_path to something different in config/initializers/refinery/core.rb

We ask that you don’t use the :as option here, as Refinery relies on it being the default of “refinery”

mount Refinery::Core::Engine, at: Refinery::Core.mounted_path

The priority is based upon order of creation: first created -> highest priority.

See how all your routes lay out with “rake routes”.

You can have the root of your site routed with “root”

root ‘refinery/pages#show’

Example of regular route:

get ‘products/:id’ => ‘catalog#view’

Example of named route that can be invoked with purchase_url(id: product.id)

get ‘products/:id/purchase’ => ‘catalog#purchase’, as: :purchase

Example resource route (maps HTTP verbs to controller actions automatically):

resources :products

Example resource route with options:

resources :products do

member do

get ‘short’

post ‘toggle’

end

collection do

get ‘sold’

end

end

Example resource route with sub-resources:

resources :products do

resources :comments, :sales

resource :seller

end

Example resource route with more complex sub-resources:

resources :products do

resources :comments

resources :sales do

get ‘recent’, on: :collection

end

end

Example resource route with concerns:

concern :toggleable do

post ‘toggle’

end

resources :posts, concerns: :toggleable

resources :photos, concerns: :toggleable

Example resource route within a namespace:

namespace :admin do

# Directs /admin/products/* to Admin::ProductsController

# (app/controllers/admin/products_controller.rb)

resources :products

end

end

the root is simply ~/workspace


#11

@BigChief45

I’m sorry, to be clear, running the server does not throw the error. The 404 comes from loading the page in my browser after I start the server.

This pops up in the terminal after starting the server:

=> Booting Puma
=> Rails 4.1.9 application starting in development on http://0.0.0.0:8080
=> Run rails server -h for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (–binding option)
=> Ctrl-C to shutdown server
Puma 2.14.0 starting…

  • Min threads: 0, max threads: 16
  • Environment: development
  • Listening on tcp://0.0.0.0:8080

The rest is from loading the homepage in a browser.


#12

Ok that makes more sense. If you are getting a 404 error it means you are accessing a view/address that does not exist in your application.

Looking at your config/routes.rb file, the root path is specified to refinery/pages#show. This means that this view file should exist in your views/refinery/pages/ directory.

Also you should check that the controller action exists in the pages controller under app/controllers directory.

Check those things and report back!

By the way, I think it’s better if you remove the default commented lines from routes.rb file, as it makes reading through it a bit harder.