{"id":491,"date":"2008-06-03T23:47:42","date_gmt":"2008-06-03T14:47:42","guid":{"rendered":"http:\/\/ecpplus.net\/weblog\/?page_id=491"},"modified":"2020-06-15T22:17:12","modified_gmt":"2020-06-15T13:17:12","slug":"activescaffold","status":"publish","type":"page","link":"https:\/\/ecpplus.net\/weblog\/activescaffold\/","title":{"rendered":"ActiveScaffold\u306e\u4f7f\u3044\u65b9"},"content":{"rendered":"<p>\u3000Rails \u3067 ActiveScaffold \u3092\u4f7f\u7528\u3059\u308b\u3068\u304d\u306b\u77e5\u3063\u3066\u304a\u304f\u3068\u826f\u3044\u4e8b\u3002<\/p>\n<h3>\u57fa\u672c\u8a2d\u5b9a<\/h3>\n<pre lang=\"ruby\">class Admin::UserController < Admin::AdminController\n  active_scaffold :user do |config|\n    config.label = '\u30e6\u30fc\u30b6\u7ba1\u7406' # \u4e00\u756a\u5de6\u4e0a\u306b\u51fa\u308b\u898b\u51fa\u3057\u306e\u6587\u5b57\u5217\u3092\u8a2d\u5b9a\n\n    # \u5404\u5217\u306e\u540d\u79f0\u3092\u8a2d\u5b9a\u3059\u308b\u3002\u4e00\u89a7\u3001\u4f5c\u6210\u753b\u9762\u306a\u3069\u3067\u8868\u793a\u3055\u308c\u308b\n    config.columns[:name].label = '\u306a\u307e\u3048'\n    config.columns[:email].label = '\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9'\n\n    # \u4f5c\u6210\u753b\u9762\u3067\u8868\u793a\u3059\u308b\u5217\u3092\u6307\u5b9a\u3059\u308b(\u5168\u90e8\u6307\u5b9a\u3059\u308b\u5f62\u5f0f)\n    config.create.columns = [:name, :created_at]\n\n    # \u4e00\u89a7\u753b\u9762\u3067\u8868\u793a\u3059\u308b\u5217\u3092\u6307\u5b9a\u3059\u308b(\u53d6\u308a\u9664\u304f\u5f62\u5f0f)\n    config.list.columns.exclude :updated_at\n\n    # \u7de8\u96c6\u753b\u9762\u3067\u8868\u793a\u3059\u308b\u5217\u3092\u6307\u5b9a\u3059\u308b(\u8ffd\u52a0\u3059\u308b\u5f62\u5f0f)\n    config.edit.columns << :telephone\n  end\nend<\/pre>\n<h4>belongs_to \u306e\u5165\u529b\u5f62\u5f0f\u3092\u30bb\u30ec\u30af\u30c8\u30dc\u30c3\u30af\u30b9\u306b\u3057\u305f\u3044<\/h4>\n<p>\u30c7\u30d5\u30a9\u30eb\u30c8\u3060\u3068\u3001belongs_to \u306e\u5165\u529b\u304c\u305d\u306e\u5834\u3067\u5165\u529b\u3057\u3066\u5909\u66f4\u51fa\u6765\u308b\u3088\u3046\u306aUI\u306b\u306a\u3063\u3066\u308b\u3002\u3053\u308c\u3092\u3001\u30bb\u30ec\u30af\u30c8\u30dc\u30c3\u30af\u30b9\u306e\u307f\u306b\u3059\u308b\u65b9\u6cd5\u3002\u4f8b\u3048\u3070\u3001 User belongs_to Company \u3068\u3044\u3046\u3068\u304d\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3059\u308b\u3002<\/p>\n<pre lang=\"ruby\">active_scaffold :user do |config|\n  config.columns[:company].form_ui = :select\n  ...\nend<\/pre>\n<p>\u516c\u5f0f\u30b5\u30a4\u30c8\u306eQ&amp;A\u304b\u306a\u3093\u304b\u306b\u3001 <code>ui_type = :select<\/code> \u3068\u3057\u306a\u3055\u3044\u3063\u3066\u66f8\u3044\u3066\u3042\u308b\u3051\u3069\u3001ActiveScaffold 2.0 \u304b\u3089 form_ui \u306b\u306a\u3063\u305f\u306e\u3067\u3053\u3063\u3061\u3092\u4f7f\u3063\u3066\u306d\u3002\u3063\u3066\u3044\u3046\u8b66\u544a\u304c\u51fa\u308b\u306e\u3067\u6ce8\u610f\u3002<\/p>\n<h4>\u8868\u793a\u3092\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3057\u305f\u3044<\/h4>\n<p>\u8868\u793a\u3092\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3059\u308b\u65b9\u6cd5\u306f\u4f55\u901a\u308a\u304b\u3042\u308b\u3002<\/p>\n<ul>\n<li>1. \u30e2\u30c7\u30eb\u306b\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30e1\u30bd\u30c3\u30c9\u3092\u5b9a\u7fa9<\/li>\n<li>2. \u30d8\u30eb\u30d1\u30e1\u30bd\u30c3\u30c9\u3092\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9<\/li>\n<\/ul>\n<h5>1. \u30e2\u30c7\u30eb\u306b\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30e1\u30bd\u30c3\u30c9\u3092\u5b9a\u7fa9<\/h5>\n<p>\u4f8b\u3048\u3070\u3001\u540d\u524d\u3068\u5e74\u9f62\u3092\u540c\u3058\u8868\u793a\u9805\u76ee\u306b\u3057\u3066 \u300c\u3061\u3085\u3046(23\u6b73)\u300d \u306e\u3088\u3046\u306a\u8868\u793a\u306b\u3057\u305f\u3044\u6642\u3001\u30e2\u30c7\u30eb\u306b\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre lang=\"ruby\">class User < ActiveRecord::Base\n  # \u306a\u307e\u3048(\u5e74\u9f62) \u3068\u3044\u3046\u5f62\u5f0f\u3067\u6587\u5b57\u5217\u3092\u8fd4\u3059\u3002\n  def name_with_age\n    \"#{self.name}(#{self.email}\u6b73)\"\n  end\n  ...\nend<\/pre>\n<p>\u305f\u3060\u3001\u3053\u308c\u3092\u5b9a\u7fa9\u3057\u305f\u3060\u3051\u3067\u306f ActiveScaffold \u304c\u5217\u3092\u62fe\u3063\u3066\u304f\u308c\u306a\u3044\u306e\u3067\u8a2d\u5b9a\u3067\u8ffd\u52a0\u3057\u307e\u3059\u3002\u4eca\u56de\u306f\u3001name_with_age= \u306e\u30e1\u30bd\u30c3\u30c9\u306f\u5b9a\u7fa9\u3057\u3066\u3044\u306a\u3044\u306e\u3067\u8868\u793a\u7cfb\u306e\u307f\u3067\u51fa\u3059\u5f62\u306b\u306a\u308a\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001\u4e00\u89a7\u753b\u9762\u306b\u51fa\u3059\u3068\u304d\u306f\u4ee5\u4e0b\u306e\u69d8\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre lang=\"ruby\">active_scaffold do |config|\n  config.list.columns << :name_with_age\n  config.columns[:name_with_age] = '\u306a\u307e\u3048(\u5e74\u9f62)'\nend<\/pre>\n<p>\u5168\u90e8\u306e\u64cd\u4f5c\u306b\u8ffd\u52a0\u3057\u305f\u3044\u3068\u304d\u306f\u3001\u4ee5\u4e0b\u306e\u69d8\u306b\u3059\u308b\u3068\u5168\u90e8\u306b\u9069\u7528\u51fa\u6765\u307e\u3059\u3002<\/p>\n<pre lang=\"ruby\">active_scaffold do |config|\n  config.columns << :name_with_age\nend<\/pre>\n<h5>2. \u30d8\u30eb\u30d1\u30e1\u30bd\u30c3\u30c9\u3092\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9<\/h5>\n<p>ActiveScaffold \u304c\u3001 #{column_name}_column \u3068\u3044\u3046\u30d8\u30eb\u30d1\u30e1\u30bd\u30c3\u30c9\u3092\u4f5c\u3063\u3066\u3044\u308b\u3088\u3046\u306a\u306e\u3067\u3001\u3053\u308c\u3092\u81ea\u5206\u3067\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3057\u3066\u3042\u3052\u308c\u3070\u3044\u3044\u307f\u305f\u3044\u3002 \u4f8b\u3048\u3070\u3001 \u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u306b mailto: \u306e\u30ea\u30f3\u30af\u3092\u3064\u3051\u305f\u3044\u3068\u304d\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3059\u308c\u3070\u3044\u3044\u3002\u30e2\u30c7\u30eb : User, \u30b3\u30f3\u30c8\u30ed\u30fc\u30e9 : Admin::UserController \u306e\u3068\u304d\u3001\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3092\u5b9a\u7fa9\u3059\u308b\u30d8\u30eb\u30d1\u306f Admin::UserHelper \u306b\u306a\u308b\u3002\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u306f email \u3068\u3059\u308b\u3002<\/p>\n<pre lang=\"ruby\">class Admin::UserHelper\n  # \u30ea\u30f3\u30af\u4ed8\u304d\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\n  def email_column(record)\n    link_to record.email, \"mailto:#{record.email}\"\n  end\nend<\/pre>\n<p>record \u306f\u3001User\u30af\u30e9\u30b9\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304c\u5165\u308a\u307e\u3059\u3002<\/p>\n<h4>\u30d5\u30a9\u30fc\u30e0\u3092\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3057\u305f\u3044<\/h4>\n<ul>\n<li>1. \u30d8\u30eb\u30d1\u30e1\u30bd\u30c3\u30c9\u3092\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9<\/li>\n<li>2. \u30d1\u30fc\u30b7\u30e3\u30eb\u3067\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9<\/li>\n<\/ul>\n<h5>1. \u30d8\u30eb\u30d1\u30e1\u30bd\u30c3\u30c9\u3092\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9<\/h5>\n<p>\u5404\u30d5\u30a9\u30fc\u30e0\u306f\u3001 #{column_name}_form_column \u3068\u3044\u3046\u30d8\u30eb\u30d1\u30e1\u30bd\u30c3\u30c9\u3067\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u51fa\u6765\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001User.name \u306e\u5165\u529b\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u5909\u66f4\u3059\u308b\u3068\u304d\u306f\u4ee5\u4e0b\u306e\u69d8\u306b\u3059\u308c\u3070\u3044\u3051\u307e\u3059\u3002:size \u3092 10 \u306b\u3057\u305f\u3060\u3051\u3060\u3051\u3069\u3001\u3061\u3083\u3093\u3068\u5909\u308f\u3063\u3066\u308b\u306e\u304c\u5206\u304b\u308b\u306f\u305a\u3002<\/p>\n<pre lang=\"ruby\">module Admin::UserHelper\n  def name_form_column(record, input_name)\n    text_field :record, :name, :size => 10\n  end\nend<\/pre>\n<p>\u5f15\u6570\u306b\u3042\u308b input_name \u306b\u306f\u3001\u4e0a\u8a18\u3060\u3068 record[name] \u3068\u3044\u3046\u6587\u5b57\u5217\u304c\u5165\u3063\u3066\u3044\u307e\u3059\u3002ActiveScaffold \u304c\u5410\u304d\u51fa\u3059HTML\u3092\u898b\u308b\u3068\u3001Rails \u306e Scaffold \u7684\u306a user[name] \u3067\u306f\u306a\u304f\u3001 record[name] \u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u306a\u306e\u3067\u3001\u4e0a\u306e\u30b3\u30fc\u30c9\u306f\u3001\u4e0b\u3068\u540c\u7fa9\u3067\u3059\u3002<\/p>\n<pre lang=\"ruby\">module Admin::UserHelper\n  def name_form_column(record, input_name)\n    text_field :record, :name, :size => 10, :name => input_name\n  end\nend<\/pre>\n<p>\u5909\u66f4\u3057\u305f\u3051\u308c\u3070\u5909\u3048\u308b\u3063\u3066\u3044\u3046\u3053\u3068\u306a\u306e\u304b\u306a\u3002<\/p>\n<p>\u305f\u3060\u3001\u3053\u308c\u3067\u5909\u66f4\u3057\u3066\u3057\u307e\u3046\u3068ActiveScaffold \u30c7\u30d5\u30a9\u30eb\u30c8\u306e CSS \u3092\u9069\u7528\u3057\u3066\u308b\u3068\u304d\u306f\u30d5\u30a9\u30fc\u30e0\u306e\u67a0\u304c\u306a\u304f\u306a\u3063\u3066\u6b8b\u5ff5\u306a\u6c17\u5206\u306b\u306a\u308b\u306e\u3067\u3001\u4f8b\u3048\u3070 text_field \u306a\u3089\u3070\u6b21\u306eDOM\u30af\u30e9\u30b9\u3092\u8db3\u3057\u3066\u3042\u3052\u308b\u3068\u826f\u3044\u3067\u3059\u3002<code>'term-input text-input'<\/code><\/p>\n<p>\u7d50\u5c40\u3001\u3053\u3093\u306a\u611f\u3058\u306b\u306a\u308b\u3002<\/p>\n<pre lang=\"ruby\">def name_form_column(record, input_name)\n  text_field :record, :name, :size => 10, :class => 'term-input text-input'\nend<\/pre>\n<p>\u7d71\u4e00\u3055\u305b\u308b\u306a\u3089\u3001\u540c\u69d8\u306e\u5f62\u5f0f\u306e\u30d5\u30a9\u30fc\u30e0\u306e\u30af\u30e9\u30b9\u3092 firebug \u306a\u3069\u3067\u898b\u3066\u771f\u4f3c\u3059\u308c\u3070\u3088\u3044\u304b\u3068\u3002<\/p>\n<h5>2. \u30d1\u30fc\u30b7\u30e3\u30eb\u3067\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9<\/h5>\n<p>form \u306e1\u8981\u7d20 + label \u3092 partial \u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304f\u3068\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u51fa\u6765\u308b\u3002<\/p>\n<p>Admin::UserController \u306b\u8a72\u5f53\u3059\u308b view \u30d5\u30a1\u30a4\u30eb\u304c\u7f6e\u304b\u308c\u308b\u3079\u304d\u30c7\u30a3\u30ec\u30af\u30c8\u30ea app\/views\/admin\/user\/ \u306b\u3001 _#{column_name}_form_column.rhtml \u3068\u3044\u3046 partial \u30d5\u30a1\u30a4\u30eb\u3092\u7f6e\u3051\u3070\u3088\u3044\u3002<\/p>\n<pre lang=\"ruby\"><label>\u306a\u307e\u3048\uff01<\/label>\n<%= text_field :record, :name, :size => 10 %><\/pre>\n<p>\u4e0a\u8a18\u306e\u3088\u3046\u306a\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u308b\u3068\u3001\u5165\u529b\u30d5\u30a9\u30fc\u30e0\u306e\u306a\u307e\u3048\u5165\u529b\u306e\u90e8\u5206\u304c\u7f6e\u304d\u63db\u308f\u308b\u3002\u305f\u3060\u3001\u4e0a\u8a18\u3060\u3068\u4ed6\u306e\u90e8\u5206\u3068 DOM \u69cb\u9020\u304c\u9055\u3063\u3066 CSS \u304c\u52b9\u304b\u306a\u304f\u3066\u6b8b\u5ff5\u306a\u8868\u793a\u306b\u306a\u308b\u3002\u3084\u306f\u308a\u4ed6\u3068\u7d71\u4e00\u3059\u308b\u306a\u3089\u771f\u4f3c\u3066\u3042\u308b\u7a0b\u5ea6\u30b3\u30d4\u30fc\u30b3\u30d4\u30fc\u3067\u3002<\/p>\n<h3>\u3042\u3068\u8abf\u3079\u308b\u3053\u3068<\/h3>\n<dl>\n<dt>nested<\/dt>\n<dd>\u95a2\u9023\u3059\u308b\u30ec\u30b3\u30fc\u30c9\u3092\u305d\u306e\u5834\u3067\u8868\u793a,\u7de8\u96c6\u51fa\u6765\u308b\u3088\u3046\u306a\u8a2d\u5b9a\u3092\u884c\u3048\u308b\u3002<\/dd>\n<dt>search<\/dt>\n<dd>\u691c\u7d22\u7cfb\u5168\u4f53\u7684\u306b\u8abf\u3079\u308b\u3002<\/dd>\n<dt>map.resources :user, :active_scaffold => true<\/dt>\n<dd>\u4eca\u77e5\u3063\u305f\u3002Flex \u3067\u3054\u306b\u3087\u3054\u306b\u3087<\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u3000Rails \u3067 ActiveScaffold \u3092\u4f7f\u7528\u3059\u308b\u3068\u304d\u306b\u77e5\u3063\u3066\u304a\u304f\u3068\u826f\u3044\u4e8b\u3002 \u57fa\u672c\u8a2d\u5b9a class Admin::UserController < Admin::AdminController active_sc [&hellip;]\n<\/p>\n","protected":false},"author":1,"featured_media":2521,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-491","page","type-page","status-publish","has-post-thumbnail","hentry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/pages\/491","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/comments?post=491"}],"version-history":[{"count":3,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/pages\/491\/revisions"}],"predecessor-version":[{"id":2558,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/pages\/491\/revisions\/2558"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/media\/2521"}],"wp:attachment":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/media?parent=491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}