ruby-http : // localhost : 3000 / admin / users를 실행하지만 redirect_to http : // localhost : 3000 / admin / login

JiaPing

저는 Ruby on Rails를 처음 사용합니다. http : // localhost : 3000 / admin / users 를 실행하여 사용자 색인 페이지를보고 싶습니다 . 하지만이 링크를 실행하면 http : // localhost : 3000 / admin / login으로 안내 합니다.

경로 설정에 문제가 있습니까?

Rails.application.routes.draw do
  get 'users/new'
  get 'users/show'

  if Rails.env.development?
    mount LetterOpenerWeb::Engine, at: '/letter_opener'
  end
  root to: 'helps#top'

  # admin login
  get 'admin/login', to: 'admin/login#index', as: 'admin/login'
  get 'admin/logout', to: 'admin/login#logout'
  post 'admin/login/login'
  get 'admin', to: 'admin/projects#index', as: 'admin_top'


  namespace :admin do
    resources :users,  only: %i(index new create)
    resources :projects do
      resources :project_users
      resources :project_comments
    end
    resources :images
    resources :categories
    resources :campanies
  end
end

users_controller.rb

class Admin::UsersController < AdminController
before_action :set_user, only: [:show, :edit, :update, :destroy]

def index
    @users = User.all
end

def show
end

def new
    @user = User.new
end

def edit    
end

#Post /admin/projects
def create
    @user = User.new(user_params)

    if @user.save
        flash[:notice] = 'User saved successfully'
        redirect_to :back
    else
        flash[:alert] = @user.errors
        binding.pry
        render :new
    end
end

def update
end

def destroy
end

private

    def set_user
        @user = User.find(params [:id])
    end

    def user_params
        params.require(:user).permit(:campany_id, :name, :email, :password_digest, :profile, :prefecture_id, :address)
    end
end

감사합니다!

Sebastian Palma 자리 표시 자 이미지

귀하 UsersControllers는 admin 네임 스페이스 아래에 있습니다. 즉, 이에 액세스하려면 로그인해야합니다.

사용자가 현재 로그인되어 있는지 확인하지 않고 액세스하려면 컨트롤러에 대한 제약 조건 또는 확인을 제거하거나 /admin/users이번에는 사용자 확인없이 가리키는 새 컨트롤러 및 인덱스 방법을 만들어야 합니다.

그게 :

# app/controllers/users_controller.rb
class UsersController < ApplicationController
  ...
  def index
    @users = User.all
  end
  ...
end

# config/routes.rb
get '/users', to: 'users#index'

'/users'또는 '/admin/users'원하는대로하지만 마지막 것을 사용하는 경우 모든 사람이 제한된 리소스라고 추론해야합니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Authentication POST http://localhost:3000/api/users/register 400 (Bad Request) MERN Application

분류에서Dev

GET http : // localhost : 3000 / 404 (찾을 수 없음), 실제로 POST를 호출하지만 GET을 얻습니다.

분류에서Dev

http : // localhost : 3000 / api / stuff에 대한 HTTP 실패 응답 : 400 잘못된 요청

분류에서Dev

Http failure response for http://localhost:3000/api/stuff: 400 Bad Request

분류에서Dev

AngularFire를 사용하는 localhost : 3000 / traceur SystemJS

분류에서Dev

Ruby on Rails는 서버 시작시 active_admin을 등록하지 않습니다 (http : // localhost : 3001 / admin).

분류에서Dev

user_path (: current)에서 "http : // localhost : 3000 / users / current"를 얻는 방법은 무엇입니까?

분류에서Dev

puma를 사용하는 Rails, localhost : 3000을 localhost : 3000 / example으로 변경

분류에서Dev

$ .getJSON은 'http : // localhost : 3000'을 api URL에 추가합니다.

분류에서Dev

http : // localhost : 3000 / entries / view_all에서 오류 발생

분류에서Dev

http : // localhost : 3000 /에 액세스 할 수 없습니다.

분류에서Dev

핫 모듈 교체가 활성화되었지만 작동하지 않음 http : // localhost : 3000 / __ webpack_hmr

분류에서Dev

인증 POST http : // localhost : 3000 / api / users / register 400 (잘못된 요청) MERN 응용 프로그램

분류에서Dev

Rails-내 서버에 "Redirected to http : // localhost : 3000"이라고 표시되어 있어도 리디렉션되지 않음

분류에서Dev

GET http : // localhost : 3000 / components / t.mp3 net :: ERR_ABORTED 404 (찾을 수 없음)

분류에서Dev

오류 : http : // localhost : 3000 / rxjs / RX (…)로드 중 XHR 오류 (404 찾을 수 없음)

분류에서Dev

angular2 rc5 http : // localhost : 3000/node_modules/@angular/forms.js로드 오류

분류에서Dev

http : // localhost : 3000 / @ angular / core로드 중 XHR 오류 (404 찾을 수 없음)

분류에서Dev

사용자를 localhost : 3000 : / : id로 표시하는 방법

분류에서Dev

사용자를 localhost : 3000 : / : id로 표시하는 방법

분류에서Dev

react에서 axios를 사용하여 localhost : 3000에서 localhost localhost : 5000을 호출 할 수없는 이유

분류에서Dev

myserver.org:3000/login/callback 대신 localhost 리디렉션

분류에서Dev

http : // localhost : 8012 대신 http : // localhost를 실행할 수 없습니다.

분류에서Dev

localhost : 3000이 노드 자습서를 렌더링하지 않습니다.

분류에서Dev

프록시 대상을 사용하여 사용자를 localhost : 3000에서 localhost : 3000 / auth / google로 가져 오는 것이 작동하지 않습니다.

분류에서Dev

`localhost : 3000 / users`를 검색하면 찾을 수 없다고합니다. 뭐가 문제 야?

분류에서Dev

제공된 대상 원본 ( 'https://docs.google.com')이 수신자 창의 원본 ( 'http : // localhost : 3000')과 일치하지 않습니다.

분류에서Dev

MIME 유형 ( 'text / html') 때문에 'http : // localhost : 3000 / style.css'에서 스타일 적용을 거부했습니다.

분류에서Dev

ejs 및 nodejs에서 POST http : // localhost : 3000 / socket.io /? EIO = 3 & transport = polling & t = NQUneY3 400 (잘못된 요청)

Related 관련 기사

  1. 1

    Authentication POST http://localhost:3000/api/users/register 400 (Bad Request) MERN Application

  2. 2

    GET http : // localhost : 3000 / 404 (찾을 수 없음), 실제로 POST를 호출하지만 GET을 얻습니다.

  3. 3

    http : // localhost : 3000 / api / stuff에 대한 HTTP 실패 응답 : 400 잘못된 요청

  4. 4

    Http failure response for http://localhost:3000/api/stuff: 400 Bad Request

  5. 5

    AngularFire를 사용하는 localhost : 3000 / traceur SystemJS

  6. 6

    Ruby on Rails는 서버 시작시 active_admin을 등록하지 않습니다 (http : // localhost : 3001 / admin).

  7. 7

    user_path (: current)에서 "http : // localhost : 3000 / users / current"를 얻는 방법은 무엇입니까?

  8. 8

    puma를 사용하는 Rails, localhost : 3000을 localhost : 3000 / example으로 변경

  9. 9

    $ .getJSON은 'http : // localhost : 3000'을 api URL에 추가합니다.

  10. 10

    http : // localhost : 3000 / entries / view_all에서 오류 발생

  11. 11

    http : // localhost : 3000 /에 액세스 할 수 없습니다.

  12. 12

    핫 모듈 교체가 활성화되었지만 작동하지 않음 http : // localhost : 3000 / __ webpack_hmr

  13. 13

    인증 POST http : // localhost : 3000 / api / users / register 400 (잘못된 요청) MERN 응용 프로그램

  14. 14

    Rails-내 서버에 "Redirected to http : // localhost : 3000"이라고 표시되어 있어도 리디렉션되지 않음

  15. 15

    GET http : // localhost : 3000 / components / t.mp3 net :: ERR_ABORTED 404 (찾을 수 없음)

  16. 16

    오류 : http : // localhost : 3000 / rxjs / RX (…)로드 중 XHR 오류 (404 찾을 수 없음)

  17. 17

    angular2 rc5 http : // localhost : 3000/node_modules/@angular/forms.js로드 오류

  18. 18

    http : // localhost : 3000 / @ angular / core로드 중 XHR 오류 (404 찾을 수 없음)

  19. 19

    사용자를 localhost : 3000 : / : id로 표시하는 방법

  20. 20

    사용자를 localhost : 3000 : / : id로 표시하는 방법

  21. 21

    react에서 axios를 사용하여 localhost : 3000에서 localhost localhost : 5000을 호출 할 수없는 이유

  22. 22

    myserver.org:3000/login/callback 대신 localhost 리디렉션

  23. 23

    http : // localhost : 8012 대신 http : // localhost를 실행할 수 없습니다.

  24. 24

    localhost : 3000이 노드 자습서를 렌더링하지 않습니다.

  25. 25

    프록시 대상을 사용하여 사용자를 localhost : 3000에서 localhost : 3000 / auth / google로 가져 오는 것이 작동하지 않습니다.

  26. 26

    `localhost : 3000 / users`를 검색하면 찾을 수 없다고합니다. 뭐가 문제 야?

  27. 27

    제공된 대상 원본 ( 'https://docs.google.com')이 수신자 창의 원본 ( 'http : // localhost : 3000')과 일치하지 않습니다.

  28. 28

    MIME 유형 ( 'text / html') 때문에 'http : // localhost : 3000 / style.css'에서 스타일 적용을 거부했습니다.

  29. 29

    ejs 및 nodejs에서 POST http : // localhost : 3000 / socket.io /? EIO = 3 & transport = polling & t = NQUneY3 400 (잘못된 요청)

뜨겁다태그

보관