Ruby on Rails
Friday, October 23, 2015
your problem it's related with CORS.
maybe it will be required to send your credentials on your request (on the JS side) too.
-- A little recipe to solve this:
1. install rack-cors gem. On your Gemfile:
# Gemfile
gem 'rack-cors', :require => 'rack/cors'
2. on shell:
bundle install
3. on your application.rb:
# application.rb
...
config.middleware.insert_before 0, "Rack::Cors" do
allow do
origins '*' # on production, use the line below instead
# origins 'localhost:3001', 'myfabulousapp.com'
resource '*', :headers => :any, :methods => [:get, :post, :delete, :put, :head]
end
end
maybe it will be required to send your credentials on your request (on the JS side) too.
I don't know if you are using angular or jquery to communicate with your API, but I made this tutorial about how to integrate angular with devise, which can be useful for you (even that you aren't using angular, some tips are on the server side):
http://www.learnwithdaniel.com/2015/10/rails-angular-authentication/
http://www.learnwithdaniel.com/2015/10/rails-angular-authentication/
--
Daniel Loureiro
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/dc179e87-06f4-4c89-b2a6-a9ea4d255cd8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment