Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 没有与[PATCH]匹配的路由”/用户/登录;设计登录_Ruby_Ruby On Rails 4_Devise_Cancan - Fatal编程技术网

Ruby 没有与[PATCH]匹配的路由”/用户/登录;设计登录

Ruby 没有与[PATCH]匹配的路由”/用户/登录;设计登录,ruby,ruby-on-rails-4,devise,cancan,Ruby,Ruby On Rails 4,Devise,Cancan,在尝试使用Desive登录rails应用程序时,我不断收到此错误: No route matches [PATCH] "/users/sign_in" 我一辈子也弄不明白为什么登录不能与Desive gem一起工作。我的路线如下: Prefix Verb URI Pattern Controller#Action root GET /

在尝试使用Desive登录rails应用程序时,我不断收到此错误:

No route matches [PATCH] "/users/sign_in"
我一辈子也弄不明白为什么登录不能与Desive gem一起工作。我的路线如下:

              Prefix Verb   URI Pattern                    Controller#Action
                root GET    /                              static_pages#home
    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
                home GET    /home(.:format)                static_pages#home
               about GET    /about(.:format)               static_pages#about
             lessons GET    /lessons(.:format)             lessons#index
                     POST   /lessons(.:format)             lessons#create
          new_lesson GET    /lessons/new(.:format)         lessons#new
         edit_lesson GET    /lessons/:id/edit(.:format)    lessons#edit
              lesson GET    /lessons/:id(.:format)         lessons#show
                     PATCH  /lessons/:id(.:format)         lessons#update
                     PUT    /lessons/:id(.:format)         lessons#update
                     DELETE /lessons/:id(.:format)         lessons#destroy
我看到补丁/用户/登录不是一个路由,但我不明白为什么它不是由Desive_为用户创建的?我的印象是,这样的调用将生成基本身份验证所需的所有路由

编辑1:

/app/views/designe/sessions/new.html.erb

<h2>Log in</h2>

<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
  <div class="field">
    <%= f.label :email %><br />
    <%= f.email_field :email, autofocus: true %>
  </div>

  <div class="field">
    <%= f.label :password %><br />
    <%= f.password_field :password, autocomplete: "off" %>
  </div>

  <% if devise_mapping.rememberable? -%>
    <div class="field">
      <%= f.check_box :remember_me %>
      <%= f.label :remember_me %>
    </div>
  <% end -%>

  <div class="actions">
    <%= f.submit "Log in" %>
  </div>
<% end %>

<%= render "devise/shared/links" %>
登录



为什么不能通过发布创建新会话?如您的路线所示:

   user_session POST   /users/sign_in(.:format)       devise/sessions#create

我们遇到了完全相同的问题。到目前为止,我找到的最佳解决方案是为补丁请求创建路由,如下所示:

as :account do
  patch '/accounts/sign_in', to: 'accounts/sessions#create'
end
请注意,我们的资源_名称是account,我们从rails的会话控制器继承,因此控制器为“accounts/sessions”

编辑:一个更好的解决方案是更改表单,以便始终创建如下新会话:

as :account do
  patch '/accounts/sign_in', to: 'accounts/sessions#create'
end
源代码的原始代码:

session_路径(:user))do | f |%>
将其更改为新操作并使用post请求:

<%= form_for(:user, :url => new_session_path(:user), :method => :post) do |f| %>
new_session_路径(:user),:method=>:post)do | f |%>

老实说,我只是在使用Desive为视图提供的功能(默认设置为修补?)。。。我修改了该代码以强制发布,但这似乎破坏了其他功能,例如:当前用户。不确定为什么…不确定,但我建议在这种情况下发布视图代码。这里有一个登录示例:我刚刚添加了它,但它直接来自Desive 3.5.2 gem。。我还没有做任何编辑,我只是猜测会话已经存在,所以表单助手将其作为更新(补丁)而不是创建(发布)。(在这种情况下,真实世界的应用程序不会向用户提供登录表单。)也许可以看看它在匿名情况下是否工作不同(这会重置会话)。如果您明确地将
method::post
添加到
form_for
?。如果删除模板并使用默认值,会发生同样的事情吗?