【问题标题】:Linking models created using Devise + Activeadmin链接使用 Devise + Activeadmin 创建的模型
【发布时间】:2014-06-24 20:33:09
【问题描述】:

我有两个模型列表和配置文件配置了 Active Admin。模型配置文件是使用设计生成的。我已经在他们之间建立了一种唯一的关系。我想创建一个系统,在该系统中,每个新列表都会自动创建和链接一个配置文件。 (想象一下airbnb,卖家只能有一个listing,不能出租)这个链接应该在activeadmin和用户登录我的应用程序时都有效。我应该如何处理这个问题。

旁注:我的模型资料不可注册。因此,通过 activeadmin 使用它很重要,这样一旦超级用户创建了列表和配置文件,我就可以将登录详细信息发送给该人,他们可以登录以查看他们的列表。

PS:Rails 新手在这里!所以更简单的方法、教程或方向将受到真正的赞赏,如果你在伦敦或伦敦附近,喝杯啤酒表示感谢。

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 devise activeadmin has-one


    【解决方案1】:

    has_one 关系见:http://guides.rubyonrails.org/association_basics.html#the-has-one-association

    如果您想在创建Listing时创建Profile,可以使用ActiveAdmin的Listing创建控制器来完成:

    代码应该是这样的:(放入app/admin/listing.rb)

    controller do
      def create
        # Create the profile.
        @profile = Profile.new
        # Create the listing and connect the profile to it.
        @listing = Listing.create(permitted_params[:name])
        @listing.profile = @profile
    
        create! do |success, failure|
          succes.html { redirect_to admin_dashboard_path}  # Or whatever path.
        end
      end
    end
    

    【讨论】:

      猜你喜欢
      • 2021-07-07
      • 1970-01-01
      • 1970-01-01
      • 2016-04-14
      • 1970-01-01
      • 2021-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多