简体   繁体   English

编辑路线不匹配路线错误GET

[英]Edit Route No Matches Routing Error GET

Hey guys I am using Rails 5. I am trying to let my users edit there info, password etc but when I go to this route. 大家好,我正在使用Rails5。我试图让我的用户在其中编辑信息,密码等,但是当我转到此路线时。

http://0.0.0.0:3000/users/edit/1 http://0.0.0.0:3000/users/edit/1

The error I get is No route matches [GET] "/users/edit/1" 我得到的错误是没有路由匹配[GET]“ / users / edit / 1”

I do have a user with an ID of 1 and I have checked in my rails console to verify. 我确实有一个ID为1的用户,并且我已经在Rails控制台中签入了以进行验证。

I have an edit template, and the edit controller and the edit method in the controller but its just not working. 我有一个编辑模板,以及控制器中的编辑控制器和编辑方法,但它无法正常工作。 What am I doing wrong? 我究竟做错了什么? All help is welcome, thank you! 欢迎所有帮助,谢谢!

ROUTES 路线

Rails.application.routes.draw do
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
  root  'pages#home'
  get  'pages/tierlist', to: 'pages#tierlist'

  resources :articles

  get 'signup', to: 'users#new'
  resource :users, except:[:new]

end

USERSCONTROLLER 用户控制器

class UsersController <ApplicationController
  def new
    @user = User.new
  end

  def create
    @user = User.create(user_params)
    if @user.save
      flash[:success] = "Welcome to the OP-OR-Nah Community #{@user.username}"
      redirect_to articles_path
    else
      render 'new'
    end
  end

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

  private
  def user_params
    params.require(:user).permit(:username, :email, :password)
  end


end

edit.html.erb edit.html.erb

<h1>Edit your info</h1>

Also when I rake routes this is what I get back 而且当我耙路线时,这就是我得到的

rake routes |grep edit
  edit_article GET    /articles/:id/edit(.:format) articles#edit
    edit_users GET    /users/edit(.:format)        users#edit

You have a typo in your file that is breaking the route. 您的文件中有一个错字,打破了路线。

Should be 应该

resources :users, except: [:new]

That route typically should look like 该路线通常看起来像

"/users/:id/edit"

when you run rake:routes. 当您运行rake:routes时。

Default url for edit is pluralize_model_name/id/edit so users/1/edit . 用于编辑的默认URL为pluralize_model_name/id/edit因此, users/1/edit Anyway, you wrote resource and not resources so I think you have not that route. 无论如何,您写的是resource而不是resources所以我认为您没有那条路。 resource is a different method that generate something like resource是一种产生类似

GET       /user/new
GET       /user
GET       /user/edit
PATCH/PUT /user
DELETE    /user
POST      /user

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM