【问题标题】:No route matches [PUT] "/users" on create action没有路线匹配 [PUT] "/users" 创建操作
【发布时间】:2018-03-21 15:00:40
【问题描述】:

我是 Ruby on Rails 的新手。我正在尝试为我的应用程序创建一个注册页面。创建新用户时出现此错误。提前非常感谢!

路线。 rb

    Rails.application.routes.draw do

  resources :users



  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end

new.html.erb

    <div class='container'>
  <div class="row">
    <div class="login col-lg-6 col-lg-offset-3">
    <%= form_for (@userInfo, :url => users_path, :method => 'post') do |f| %>
      <label>First Name</label><%= f.text_field(:first_name) %><br/><br/>
      <label>Last Name</label><%= f.text_field(:last_name) %><br/><br/>
      <label>Email</label><%= f.text_field(:email) %><br/><br/>
      <label>Password</label><%= f.text_field(:password) %><br/><br/>
      <label>Date of Birth</label><%= f.text_field(:dob) %><br/><br/>
      <label>Contact No.</label><%= f.text_field(:contactno) %><br/><br/>
      <%= f.submit('Register User') %>

    <% end %>
    </div>
  </div>
</div>

用户控制器

    class UsersController < ApplicationController

  layout 'HomeLayout'

  def new
      @userInfo = TblUserInformation.new
  end

  def create
    @userInfo = TblUserInformation.new(params[:user])
    @userInfo.save
  end
end

【问题讨论】:

  • rake routes 的输出是什么?我的直觉告诉我你应该使用 new_user_path 或类似的东西
  • 可以输出rake routes吗?
  • users_path 可能是您的索引路由的路由。试试 new_user_path
  • users GET /users(.:format) users#index POST /users(.:format) users#create new_user GET /users/new(.:format) users#new edit_user GET /users/ :id/edit(.:format) users#edit user GET /users/:id(.:format) users#show PATCH /users/:id(.:format) users#update PUT /users/:id(.:格式) users#update DELETE /users/:id(.:format) users#destroy

标签: ruby model-view-controller routes ruby-on-rails-5


【解决方案1】:

正如您的rails routes 向您展示的那样:
POST /users(.:format) users#create new_user
您必须在 form_for url 属性中使用 new_user_path

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多