Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.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 单视图中的2种不同型号登录表单,Rails 4和Desive_Ruby On Rails_Ruby On Rails 3_Devise - Fatal编程技术网

Ruby on rails 单视图中的2种不同型号登录表单,Rails 4和Desive

Ruby on rails 单视图中的2种不同型号登录表单,Rails 4和Desive,ruby-on-rails,ruby-on-rails-3,devise,Ruby On Rails,Ruby On Rails 3,Devise,我已经为广告和用户创建了模式登录表单。他们完全不同 我的目标是创建在同一视图中作为用户或广告登录的功能。因此,访问者选择登录为用户->用户登录表单显示等 在一些资料中,我读到我需要在Application_helper中添加一些行,以便能够从任何地方以用户身份登录 应用程序\u helper.rb def resource_name :user #tried thing below :user, :advertisement # got syntax error fro

我已经为广告用户创建了模式登录表单。他们完全不同

我的目标是创建在同一视图中作为用户或广告登录的功能。因此,访问者选择登录为用户->用户登录表单显示等

在一些资料中,我读到我需要在Application_helper中添加一些行,以便能够从任何地方以用户身份登录

应用程序\u helper.rb

def resource_name
    :user

    #tried thing below
    :user, :advertisement # got syntax error from this line.

  end

  def resource
    @resource ||= User.new
  end

  def devise_mapping
    @devise_mapping ||= Devise.mappings[:user]

  end
class Advertisement < ActiveRecord::Base
 devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :authentication_keys => [:name]
 include Humanizer
  require_human_on :create

 .......


end
我尝试了此代码的不同变体

但没有结果

我的登录表单如下所示:

<%= form_for(resource,:html => {id:"form-signin"}, as: resource_name, url: session_path(resource_name)) do |f| %>

    ....

<%end%>
广告.rb

def resource_name
    :user

    #tried thing below
    :user, :advertisement # got syntax error from this line.

  end

  def resource
    @resource ||= User.new
  end

  def devise_mapping
    @devise_mapping ||= Devise.mappings[:user]

  end
class Advertisement < ActiveRecord::Base
 devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :authentication_keys => [:name]
 include Humanizer
  require_human_on :create

 .......


end
类广告[:名称] 包括人性化者 需要人力资源:创建 ....... 结束 任何帮助都会很好。
谢谢。

您的用户和广告模型看起来如何?@kurenn用一些代码更新了我的问题。您是否尝试重新启动服务器?为什么要覆盖
ApplicationHelper
上的方法?@kurenn是的,我尝试重新启动。没有变化。因为这是能够从任何控制器操作登录的唯一方法。我在应用程序布局中有登录部分。看看它可能会帮助您设置此多角色问题
class Advertisement < ActiveRecord::Base
 devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :authentication_keys => [:name]
 include Humanizer
  require_human_on :create

 .......


end