- 如何覆盖日期或时间的活动脚手架表单字段?(datepicker 和 calendar_date_select 对我不起作用,可能是因为我正在使用 activescaffold gem)
- 如何覆盖 Active Scaffold 表单以从数据库中的资源列表中进行选择?
谢谢。
谢谢。
我一直在努力解决这个问题,直到我弄清楚了。这是一个例子:
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