ruby on rails - RoR: curl "upload completely sent off" -
rails version: 2.2.4. ruby version: 5.0.0.1 curl version: 7.50.1
hello people,
i new ruby on rails programmer , need programm university authentication function ruby on rails through json request , on end can use authentication-function directly on android app.
after hours of work made can registrate , login ruby on rails. followed deprecated tutorial (http://lucatironi.net/tutorial/2012/10/15/ruby_rails_android_app_authentication_devise_tutorial_part_one/) , see how authentication function through json request.
update: think messed create sessions controller right. created this: controllers/api/v1/sessions_controller.rb data , put text in it:
class api::v1::sessionscontroller < devise::sessionscontroller skip_before_filter :verify_authenticity_token, :if => proc.new { |c| c.request.format == 'application/json' } respond_to :json def create warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#failure") render :status => 200, :json => { :success => true, :info => "logged in", :data => { :auth_token => current_user.authentication_token } } end def destroy warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#failure") current_user.update_column(:authentication_token, nil) render :status => 200, :json => { :success => true, :info => "logged out", :data => {} } end def failure render :status => 401, :json => { :success => false, :info => "login failed", :data => {} } end end
then addded on routes.rb namespace:api do..
rails.application.routes.draw 'home/index' 'welcome/index' devise_for :users resources :users # details on dsl available within file, see http://guides.rubyonrails.org/routing.html root to: "home#index" namespace :api namespace :v1 devise_scope :user post 'sessions' => 'sessions#create', :as => 'login' delete 'sessions' => 'sessions#destroy', :as => 'logout' end end end end
then want test login , logout function, creating test user first:
user = user.new(:name => 'testuser', :email => 'user@example.com', :password => 'secret', :password_confirmation => 'secret') user.skip_confirmation! user.save
after start rails server rubymine , after use curl invoke new login api:
curl -v -h 'content-type: application/json' -h 'accept: application/json' -x post http://localhost:3000/api/v1/sessions -d "{\"user\":{\"email\":\"user@example.com\",\"password\":\"secret\"}}"
now here comes error curl: upload sent off: 60 out of 60 bytes:
enter image description here know whats wrong? think did not set sessions-controller right. if
Comments
Post a Comment