如何使用轨道上的宝石创建漂亮的表单active_scaffold 3.


  1. 如何覆盖日期或时间的活动脚手架表单字段?(日期选择器和calendar_date_select可能对我不起作用因为我正在使用活动支架宝石)
  2. 如何覆盖活动基架窗体以从数据库?

谢谢。

我一直在努力解决这个问题,直到我想通了。下面是一个示例:

class Player < ActiveRecord::Base
  belongs_to :game
  attr_accessible :name
end
class Game < ActiveRecord::Base
  has_many :players 
  attr_accessible :thedate, :thetime, :winnername
end
class GamesController < ApplicationController
  active_scaffold :game do |conf|
    # do nothing in this example
  end
end
module GamesHelper
  # date select
  def game_thedate_form_column (record, options)
    date_select :record, :thedate, options
  end
  # time select
  def game_thetime_form_column (record, options)
    time_select :record, :thetime, options
  end
  # select from database resources
  def game_winnername_form_column (record, options)
    select_tag :winnername, options_for_select(get_players_names_arr(record)), options
  end
  def get_players_names_arr(game)
    names = []
    game.players.each do |player|
      names << player.name
    end
    names 
  end
end

相关内容

  • 没有找到相关文章

最新更新