Showing posts with label Ruby on Rails. Show all posts
Showing posts with label Ruby on Rails. Show all posts

Saturday, March 30, 2019

Cross-Origin Resource Sharing in Ruby on Rails Application

While working in Ruby on Rails application I faced a problem with Cross-Origin Resource Sharing. Here is the configuration below how to sort out this problem:


Rack::Cors provides support for Cross-Origin Resource Sharing



Steps to enable rackcors :


1.add gem to your Gemfile:

gem 'rack-cors'
2.Add below code to config/application.rb

# if you are using Rails 3/4
config.middleware.insert_before 0, "Rack::Cors" do
  allow do
    origins '*'
    resource '*', :headers => :any, :methods => :any
  end
end

# if you are using Rails 5

config.middleware.insert_before 0, Rack::Cors do
  allow do
    origins '*'
    resource '*', headers: :any, methods: :any
  end
end

Friday, March 29, 2019

Ruby on Rails Basic Commands

To create app:

rails new your_app

To start server:

rails s or rails server

To remove model:

bundle exec rake db:rollback 

rails destroy model <model_name>

To clear db:

rails db:purge
rails db:migrate

rails db:seed

Or all together.

rails db:purge db:migrate db:seed