簡體   English   中英

Rails 3為沒有表支持的模型生成控制器

[英]Rails 3 generate controller for a model not backed by a table

我的Rails 3.1應用程序中有一個沒有表支持的模型。 實際上,我什至沒有繼承ActiveModel(這可能是一個錯誤...)。

我真的想使用生成器來創建視圖,因為此模型具有67個attrs(用戶偶爾要指定某個attr中的內容,而其他時候將其設置為默認值)。

當我運行rails g controller TestDataRecords index show edit new destroy create update我沒有預先填充視圖。

有什么想法嗎?

模型

class TestDataRecord
  belongs_to :test_data_set

  attr_accessor :sample_attr # repeat 66 times


  def after_initilize
    return unless new_record?
    self.sample_attr = "default value"
  end
end

檢出: https : //github.com/ryanb/nifty-generators ,它是一個很棒的寶石,它可以讓您選擇要為其生成視圖的控制器動作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM