Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.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 on rails 使用Desive进行身份验证的Ruby应用程序_Ruby On Rails_Ruby_Devise_Crud - Fatal编程技术网

Ruby on rails 使用Desive进行身份验证的Ruby应用程序

Ruby on rails 使用Desive进行身份验证的Ruby应用程序,ruby-on-rails,ruby,devise,crud,Ruby On Rails,Ruby,Devise,Crud,我正在开发一个简单的应用程序,允许会员创建一次旅行。只有一次旅行。我想获得一些使用Desive gem的实践,以便设置具有登录、注销等功能的应用程序既简单又高效,但我需要一些帮助。现在我有两种型号:member和trip,它们都没有控制器 这是我的注册表单,当我单击“提交”时,不知何故,即使没有成员控制器,也会在数据库中创建一个成员?按下submit后,如何将其重定向到其他页面 我只是有点困惑我应该添加什么,因为Desive在幕后做了很多工作 <h2>Sign up</h2&g

我正在开发一个简单的应用程序,允许会员创建一次旅行。只有一次旅行。我想获得一些使用Desive gem的实践,以便设置具有登录、注销等功能的应用程序既简单又高效,但我需要一些帮助。现在我有两种型号:member和trip,它们都没有控制器

这是我的注册表单,当我单击“提交”时,不知何故,即使没有成员控制器,也会在数据库中创建一个成员?按下submit后,如何将其重定向到其他页面

我只是有点困惑我应该添加什么,因为Desive在幕后做了很多工作

<h2>Sign up</h2>

<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>

<div><%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %></div>

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

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

<div><%= f.submit "Sign up" %></div>
<% end %>
注册




您可以创建一个控制器来执行此操作

class UserController < Application::Base
  def new
    @user = User.new
  end

  def create
    @user = User.new(email: params[:email], password: params[:password],      password_confirmation: params[:password_confirmation])
  if @user.save
    redirect_to <page you want to redirect to>
  else
    render new
  end
end
class UserController
Deviate提供了一些宏,您可以覆盖这些宏来选择要重定向到的路径

class RegistrationsController < Devise::RegistrationsController
  protected

  def after_sign_up_path_for(resource)
    '/an/example/path'
  end
end
在有人注册后,将
/an/example/path
替换为您想要重定向到的任何路径。然后通过添加以下行修改
config/routes.rb
以指向该控制器:

devise_for :members, :controllers => { :registrations => "registrations" }
然后,您可能需要通过添加此行编辑您的
config/application.rb

config.paths['app/views'] << "app/views/devise"
config.path['app/views']
  • 用户(或者在您的情况下是成员)控制器只是在设计gem内部进行通信
  • 要将用户重定向到
    user/home
    ,您可以通过以下方式在
    routes.rb
    文件中定义
    user\u root
    路由:

    获取'user/home',如:'user\u root'

    阅读更多


  • 是的,但当我点击注册时,它会自动带我回家。假设我想重定向到另一个路由/路径,如何/在何处插入?更改
    'user/home'
    以了解您需要的内容(在上面的行中)。是的,但当我单击“注册”时,它会自动将我带回家中。假设我想重定向到另一个路由/路径,如何/在何处插入它?我链接到的源是关于如何修改设计默认行为的逐步说明。但是我已经编辑了我的答案,加入了说明太棒了!您是否认为在成功登录后也有类似的方法可以做到这一点?我以前构建过crud应用程序,但Desive是一个全新的东西。根据他们的文档,在为(资源)登录路径后,您将使用
    
    
    config.paths['app/views'] << "app/views/devise"