Ruby on rails rails会无理由自动更改路线

Ruby on rails rails会无理由自动更改路线,ruby-on-rails,ruby-on-rails-4,rails-routing,Ruby On Rails,Ruby On Rails 4,Rails Routing,我的注册路径中有以下注册表单,该表单映射到“新用户” 在my new.html.erb中 <%= form_for(@user) do |f|%> <!---handles the error messages within the form. --> <%= render "shared/error_messages"%>

我的注册路径中有以下注册表单,该表单映射到“新用户”

在my new.html.erb中

            <%= form_for(@user) do |f|%>

                    <!---handles the error messages within the form. -->
                    <%= render "shared/error_messages"%>

                    <%= f.label :name%>
                    <%= f.text_field :name, class: 'form-control'%></br>

                    <%= f.label :email%>
                    <%= f.text_field :email, class: 'form-control'%></br>

                    <%= f.label :password%>
                    <%= f.password_field :password, class: 'form-control'%></br>

                    <%= f.label :password_confirmation, "Confirmation"%>
                    <%= f.password_field :password_confirmation, class: 'form-control' %></br>

                    <%= f.submit "Create My Account!", class:"btn btn-theme btn-block"%>

                <%end%>
现在我可以在localhost:3000/signup上成功注册新用户,这非常理想。但是,每当我尝试将部分或所有字段留空来测试表单时,它都会将我重定向到localhost:3000/users。我想我的控制器可能有问题,但我找不到任何奇怪的地方

用户_controller.rb

class UsersController < ApplicationController
    # before accessing the only and edit RESTful thing, go to logged_in_user first. 
    before_action :logged_in_user, only: [:edit, :update, :index, :destroy]
    before_action :correct_user, only: [:edit, :update]
    before_action :admin_user, only: [:destroy]


    def index
        @users = User.all
    end

    def new
        # create a new user!
        @user = User.new
    end

    def show
        # declare a user variable, assign it to the current user
        @user = User.find(params[:id])
    end

    def create
        @user = User.new(user_params)
        if @user.save
            #before we watned to log the user in after they create their account, now we want them to activate their emails

            #log_in @user
            #flash[:success] = "Welcome!"
            #redirect_to @user

            @user.send_activation_email
            flash[:info] = "Please check your email to activate your account."
            redirect_to login_url
        else
            render "new"
        end
    end
class UsersController

我做错了什么?为什么路线在改变?我试图将\u重定向到注册路径,而不是呈现“新”,但如果我这样做,则错误消息将消失,这是我不希望看到的

现在您的登录表单发布到
/users
,因此当您
呈现“new”
时,显示的url是正确的。如果你想改变这种行为,你可以将“注册”=>“用户创建”
添加到你的路线中,这样你就可以将表单发布到
/signup
中,当你从
创建
操作中呈现“新建”时,它会显示你想要的url。

我在我的路线中添加了“注册”=>“用户创建”,但不幸的是,这种行为仍然是一样的。我是否遗漏了什么,尤其是“将表单发布到/注册…”这一行?
应该发布到正确的位置。这给了我一个语法错误。我尝试了上面的方法和:url=>signup\u path,但都返回语法错误。rails 4.1有什么新功能吗?我修好了!结果表明,url需要位于表单_的参数内
class UsersController < ApplicationController
    # before accessing the only and edit RESTful thing, go to logged_in_user first. 
    before_action :logged_in_user, only: [:edit, :update, :index, :destroy]
    before_action :correct_user, only: [:edit, :update]
    before_action :admin_user, only: [:destroy]


    def index
        @users = User.all
    end

    def new
        # create a new user!
        @user = User.new
    end

    def show
        # declare a user variable, assign it to the current user
        @user = User.find(params[:id])
    end

    def create
        @user = User.new(user_params)
        if @user.save
            #before we watned to log the user in after they create their account, now we want them to activate their emails

            #log_in @user
            #flash[:success] = "Welcome!"
            #redirect_to @user

            @user.send_activation_email
            flash[:info] = "Please check your email to activate your account."
            redirect_to login_url
        else
            render "new"
        end
    end