Comments (20)
That is why, you have to change that to respond to a path instead of an api as discussed in here #52
from market_place_api.
I found the reason. It should POST http://api.myapi2.dev/users. The URI /users/sign_up(.:format) is to request the sign up form page.
_But_ there is a new issue. After I submit by click the Send button, it can create new user successfully in database, but Postman still result in errors. Why?
from market_place_api.
You should post to the users
controller create
action, do you have an example on how it looks like?
from market_place_api.
api_users POST /users(.:format) api/v1/users#create {:format=>:json, :subdomain=>"api"}
user_registration POST /users(.:format) devise/registrations#create
Yes, but the URI /users
has two match. It seem to match with the first one. I don't known why.
What does example mean?
from market_place_api.
You can remove the devise routes, they are not being used
from market_place_api.
I can't remove it directly. Because i add devise email confirmation for register.
It add three routes:
user_confirmation POST /users/confirmation(.:format) devise/confirmations#create
new_user_confirmation GET /users/confirmation/new(.:format) devise/confirmations#new
GET /users/confirmation(.:format) devise/confirmations#show
The first one is need. Is there a way to remove the useless devise routes only?
from market_place_api.
remove then the :registrable
module from the user model that should work!
from market_place_api.
I just try it, it worked! Many thanks!
from market_place_api.
I think the forms GET routes should remove too.
Such as:
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
but retain the POST routes:
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
How can i do it?
from market_place_api.
It has to be with the devise modules, maybe the recoverable
? or some other....
from market_place_api.
Hi,
from reading this I think one should link this issue with the following issue: #8
Seems that they're about the same things regarding devise routes an the apionrails user controller routes.
Any idea how to solve the "duplicate" routes?
From my point of view the don't use devise options like "recoverable" won't solve the issue.
As I understand we choose devise for the authentication stuff and won't get rid of it.
What about not using the apionrails user controller routes?
Best
Jan
from market_place_api.
Yeah that, could be a good solution, not to use the users_controller
but we will have to override the one on devise.
A good solution would be as describe on issue #8 just move the devise_for :users
call after the :api
namespace...
from market_place_api.
@kurenn thanks for your reply :-)
When I move the the devise_for :users call after the :api namespace the routes are listed beneath our :api path. Thats fine, but we do have duplicate routes now.
When I bundle exec rspec spec all tests passes. Thats fine.
But our specs are using our own user / session controllers and not the ones of devise.
Question:
Why we are not using the devise controllers?
Don't we want to use devise for the heavy authentication stuff, register a new user, sign in, sign out etc.?
Devise don't return json responses when used as is. Shouldnt we inherit from the devise controllers?
When I don't use the above "hack" (remove then the :registrable module from the user model) and try to use postman to create a user I'm getting "routing error - uninitialized constant Api::V1::RegistrationsController" due to the routes "mismatch" of our own and of the devise routes.
My rake routes:
Prefix Verb | URI Pattern | Controller#Action |
---|
new_api_user_session GET | /users/sign_in(.:format) | api/v1/sessions#new {:format=>:json, :subdomain=>"api"}
api_user_session POST | /users/sign_in(.:format) | api/v1/sessions#create {:format=>:json, :subdomain=>"api"}
destroy_api_user_session DELETE | /users/sign_out(.:format) | api/v1/sessions#destroy {:format=>:json, :subdomain=>"api"}
api_user_password POST | /users/password(.:format) | api/v1/passwords#create {:format=>:json, :subdomain=>"api"}
new_api_user_password GET | /users/password/new(.:format) | api/v1/passwords#new {:format=>:json, :subdomain=>"api"}
edit_api_user_password GET | /users/password/edit(.:format) | api/v1/passwords#edit {:format=>:json, :subdomain=>"api"}
PATCH | /users/password(.:format) | api/v1/passwords#update {:format=>:json, :subdomain=>"api"}
PUT | /users/password(.:format) | api/v1/passwords#update {:format=>:json, :subdomain=>"api"}
cancel_api_user_registration GET | /users/cancel(.:format) | api/v1/registrations#cancel {:format=>:json, :subdomain=>"api"}
api_user_registration POST | /users(.:format) | api/v1/registrations#create {:format=>:json, :subdomain=>"api"}
new_api_user_registration GET | /users/sign_up(.:format) | api/v1/registrations#new {:format=>:json, :subdomain=>"api"}
edit_api_user_registration GET | /users/edit(.:format) | api/v1/registrations#edit {:format=>:json, :subdomain=>"api"}
PATCH | /users(.:format) | api/v1/registrations#update {:format=>:json, :subdomain=>"api"}
PUT | /users(.:format) | api/v1/registrations#update {:format=>:json, :subdomain=>"api"}
DELETE | /users(.:format) | api/v1/registrations#destroy {:format=>:json, :subdomain=>"api"}
api_users POST | /users(.:format) | api/v1/users#create {:format=>:json, :subdomain=>"api"}
api_user GET | /users/:id(.:format) | api/v1/users#show {:format=>:json, :subdomain=>"api"}
PATCH | /users/:id(.:format) | api/v1/users#update {:format=>:json, :subdomain=>"api"}
PUT | /users/:id(.:format) | api/v1/users#update {:format=>:json, :subdomain=>"api"}
DELETE | /users/:id(.:format) | api/v1/users#destroy {:format=>:json, :subdomain=>"api"}
api_sessions POST | /sessions(.:format) | api/v1/sessions#create {:format=>:json, :subdomain=>"api"}
api_session DELETE | /sessions/:id(.:format) | api/v1/sessions#destroy {:format=>:json, :subdomain=>"api"}
Question
I guess the crucial part to use of devise is the registration / password recover process etc.
So how can we use the crucial parts of devise and then use our "own" controllers for the "simple" stuff as showing, updating the user?
In future version one can image to use devise omniauth feature to register users with out api app that are google+ or twitter or etc. user.
Best
Jan
from market_place_api.
@kurenn Also curious to @janotterstetter 's question. Could you help us out please?
from market_place_api.
@janotterstetter Yeah you could use devise to register users, but you will have to override the registrations controller from devise to meet your needs, and on the tutorial I wanted to keep it super simple to register users.
Now to get the users controller create action to work, using postman:
Please let me know how it goes, sorry for the delay on the answer!
from market_place_api.
I'm not sure how to test. I'm using localhost:3000, and none of my postman stuff works. Does this have to be loaded on a server to test the API?
from market_place_api.
Do you have the subdomain setup on your routes file?
from market_place_api.
Yes.
from market_place_api.
Thanks for getting back to me last time. I appreciate it. I took a crack at your ticket suggestion and implemented it in my routes as seen below.
Now, I’m getting all kinds of timeouts and routing errors. I’m hoping that things are working as I go through, but I’m almost done with the book and have no idea if anything I’m doing is working on the API end, though the tests work great. I attached my log.
What am I doing wrong here?
Here is my routes
require 'api_constraints'
HapnApp::Application.routes.draw do
mount SabisuRails::Engine => "/sabisu_rails"
devise_for :users
namespace :api, path: '/api' do
scope module: :v1,
constraints: ApiConstraints.new(version: 1, default: true) do
resources :users, :only => [:show, :create, :update, :destroy]
resources :sessions, :only => [:create, :destroy]
resources :events, :only => [:show, :index]
end
end
end
All I really need to know at the end of this is:
- What is the URL I’m going to access to get my resource information, both as I develop on my local machine and then again on Heroku?
- How do I test this URL as I’m creating my site?
I know this can’t be difficult once you learn it, but man, it seems a long way off.
Thanks,
Rich
On Nov 26, 2015, at 7:01 PM, Abraham <[email protected]mailto:[email protected]> wrote:
That is why, you have to change that to respond to a path instead of an api as discussed in here #52#52
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/33#issuecomment-160007925.
from market_place_api.
@lesreaper Now you will have to access the resources like:
api/v1/users/
or whatever you want to access
from market_place_api.
Related Issues (20)
- Body is blank.? --I can not do DELETE/ POST / PUT / interface Sabisu_Rails HOT 3
- Listing: 6.5: Failure/Error: @user.destroy HOT 1
- Chapter 6 should_not be_published HOT 1
- Unable to access api endpoint (via cURL and in browser) HOT 1
- Found an error in the beginning of Chapter 8.1
- Latest updates of this project HOT 4
- Chapter 10 Pagination issue: Meta object in render json: products, meta: is not rendered in ActiveModelSerializer 0.10.2 HOT 1
- json render format; chapter 7 HOT 1
- Filter chain halted as :authenticate_with_token! rendered or redirected Completed 401 Unauthorized HOT 3
- Rspec test failing in Rails 5 HOT 6
- Rails 5.0.1: Sass::SyntaxError in SabisuRails::Explorer#index HOT 5
- Listing 5.12 HOT 3
- How do I do a log out(destroy the session) using cUrl? HOT 5
- 500 error when user not exist HOT 5
- sign_in in sessions controller does not affect tests HOT 4
- Chapter 6.1.3 Dependency Destroy Factory HOT 3
- I have been getting a 404 for the same request which is successful on another POSTMAN. HOT 1
- Chapter 6.2.6: ActionController::UrlGenerationError: No route matches {:action=>"destroy", :controller=>"api/v1/products" ... HOT 1
- Chapter 6 ActionController::UrlGenerationError:
- Chapter 5 Authentication Rails 5.2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from market_place_api.