这是错误:
Started GET "/javascripts/vendor/custom.modernizr.js" for ::1 at 2016-04-09 12:42:41 +0800
ActionController::RoutingError (No route matches [GET] "/javascripts/vendor/custom.modernizr.js"):
actionpack (4.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
web-console (2.3.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `catch'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `call'
我创建了一些关于某些用户群信息的用户索引。
class UsersController < ApplicationController
before_action :set_user
before_action :owned_user, only: [:edit, :update]
def index
@user = User.all
end
def edit
@user = User.find_by(name: params[:name])
end
def update
if @user.update(user_params)
flash[:success] = 'Your profile has been updated.'
redirect_to user_path(@user.name)
else
@user.errors.full_messages
flash[:error] = @user.errors.full_messages
render :edit
end
end
private
def user_params
params.require(:user).permit(:name, :email, :password, :avatar)
end
def owned_user
unless current_user == @user
flash[:alert] = "That profile doesn't belong to you!"
redirect_to root_path
end
end
def set_user
@user = User.find_by(name: params[:name])
end
end
class User < ActiveRecord::Base
mount_uploader :avatar, AvatarUploader
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
validates :name, presence: true, length: { minimum: 4, maximum: 16 }
end
关于观点/设计,我没有改变任何东西。 这是我的routes.rb
Rails.application.routes.draw do
resources :topics
devise_for :users
resources :nodes
root 'topics#index'
get ':name', to: 'users#index', as: :users
get ':name/edit', to: 'users#edit', as: :edit_user
patch ':name/edit', to: 'users#update', as: :update_user
end
这是路线:
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format)devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format)devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
users GET /:name(.:format) users#index
edit_user GET /:name/edit(.:format) users#edit
update_user PATCH /:name/edit(.:format) users#update
谢谢你帮助我,我很难解决问题。我是新人,期待设计,登录/退出是否有更好的宝石?
答案 0 :(得分:1)
我认为你的控制器路线&amp;设计路线可能会有冲突。尝试使用其他名称创建另一个控制器,例如Admin :: UsersController。
在/app/controllers/admin/users_controller.rb中创建一个文件并尝试下面的代码。
class Admin::UsersController < ApplicationController
before_filter :authenticate_user!
before_action :set_user, only: [:show, :edit, :update, :destroy]
def index
end
def show
end
def new
@user = User.new
end
def edit
end
def create
@user = User.new(user_params)
respond_to do |format|
if @user.save
format.html { redirect_to [:admin, @user], notice: 'User is created.' }
format.json { render :show, status: :created, location: @user }
else
format.html { render :new }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if @user.update_without_password(user_params)
format.html { redirect_to [:admin, @user], notice: 'User is updated.' }
format.json { render :show, status: :ok, location: @user }
else
format.html { render :edit }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
def destroy
@user.destroy
respond_to do |format|
format.html { redirect_to admin_users_url, notice: 'User is destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_user
@user = User.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def user_params
params.require(:user).permit(:email, :password, :password_confirmation, :current_password)
end
end
当然还有你的routes.rb
namespace :admin do
resources :users
end
希望有所帮助