1. Install
./script/plugin install git://github.com/activescaffold/active_scaffold.git -r rails-2.3
Rails 2.3.x needs the plugin render_component for nested scaffolds
./script/plugin install git://github.com/ewildgoose/render_component.git -r rails-2.3
Getting Started : http://wiki.github.com/activescaffold/active_scaffold/getting-started
2. Configuration
1) Model
Security
On your model object you may define methods (none of which accept any arguments) in any of four formats, depending on your need for granularity.
The formats are:
* #{column_name}_authorized_for_#{crud_type}?
* #{column_name}_authorized?
* authorized_for_#{crud_type}?
* authorized_for_#{action_name}?
http://wiki.github.com/activescaffold/active_scaffold/security
eg: Company
def authorized_for_delete?
current_user.is_admin? || Role.is_company_admin(current_user)
end
def authorized_for_update?
current_user.is_admin? || Role.is_company_admin(current_user)
end
def authorized_for_create?
current_user.is_admin? || Role.is_company_admin(current_user)
end
Task
def original_hours_authorized_for_update?
current_user.is_admin? || Role.is_company_admin(current_user)
end
named_scope
When you use beginning_of_chain method on controller, you can use model named_scope to limit the collection.
Tip: ”:joins” (ActiveRecord readonly), ”:include”
2) Controller
DataGrid
config.columns = [...]
list.columns.exclude :attribute1, :attribute2
update.columns.exclude :attribute1, :attribute2
create.columns.exclude ::attribute1, :attribute2
show.columns.exclude ::attribute1, :attribute2
eg: stories_controller.rb
active_scaffold :story do |config|
config.columns = [:title, :description, :idealdays, :priority, :state, :iteration, :tasks, :user, :comments, :project, :labels]
list.columns.exclude :comments, :tasks
update.columns.exclude :comments, :tasks, :project, :labels
create.columns.exclude :comments, :tasks, :project
show.columns.exclude :comments, :tasks
columns[:user].label = "Assign to User"
columns[:idealdays].label = "Ideal Days"
config.columns[:user].actions_for_association_links = [:show]
config.columns[:iteration].actions_for_association_links = [:show]
config.columns[:project].actions_for_association_links = [:show]
config.nested.add_link("Tasks", [:tasks])
config.nested.add_link("Comments", [:comments])
config.columns[:state].form_ui = :select
config.columns[:state].options = {:options => ["Please estimate ideal days"].map(&:to_sym)}
config.columns[:user].form_ui = :select
config.columns[:iteration].form_ui = :select
config.columns[:description].form_ui = :text_editor
config.columns[:labels].form_ui = :select
config.columns[:priority].form_ui = :select
config.columns[:priority].options = {:include_blank => "none", :options => 1..5}
config.subform.layout = :vertical
config.list.empty_field_text = "none"
end
Form
config.columns[:field_name].form_ui # value :boolean, :calendar)date_select, :checkbox, :country, :select....
http://wiki.github.com/activescaffold/active_scaffold/api-column
Labels
config.columns[:field_name].label = "Some text"
Collection Condition
conditions_for_collection, beginning_of_chain(use named_scope)
http://wiki.github.com/activescaffold/active_scaffold/api-list
eg: stories_controller.rb
def beginning_of_chain
if !is_admin
super.for_common_user(current_user.projects)
elsif Role.is_company_admin(current_user)
super.for_company_admin(current_user.company)
else
super
end
end
#{before,after}_#{create,update}_save
eg: stories_controller.rb
def before_create_save(record)
record.project = @parent unless @parent.nil?
end
Security
#{action_name}_authorized?
http://wiki.github.com/activescaffold/active_scaffold/security
eg: users_controller.rb
def add_existing_authorized?
false
end
3) Helper
Form Association Options(exclude: edit)
When you create a task_session, you want to limit the users with your company.
options_for_association_conditions(association)
eg: users_helper.rb
def options_for_association_conditions(association)
if association.name == :users
['company_id = ?', current_user.company.id] unless current_user.is_admin?
elsif association.name == :roles
['roles.id != ?', Role.find_by_name(Role::ROLE_ADMINISTRATOR).id] unless current_user.is_admin?
else
super
end
end
http://wiki.github.com/activescaffold/active_scaffold/custom-association-options
Field Overrides
#{column_name}_column(record)
eg: stories_helper.rb
def labels_column(record)
temp = record.labels.inject([]){|result, label| label.user == current_user ? result << h(label.name) : result }
if temp.any?
temp.join(",")
else
# This way there's something to turn into a link if there are no roles associated with this record yet.
active_scaffold_config.list.empty_field_text
end
end
http://wiki.github.com/activescaffold/active_scaffold/field-overrides
Form Overrides
http://wiki.github.com/activescaffold/active_scaffold/form-overrides
4) View
Template Overrides
Rendering your template overrides will wrap in this order:
1. Wrapping Template
2. ActiveScaffold Global Template Overrideapp/views/active_scaffold_overrides/template.html.erb
3. ActiveScaffold Frontendvendor/plugins/active_scaffold/frontends/default/views/template.html.erb
http://wiki.github.com/activescaffold/active_scaffold/template-overrides
3. Tips
ID (How to get id ? Nested page)
session_index = "as:#{params[:eid]}"
session[session_index][:constraints].values.to_s.to_i
Frequency Template Override
_list_actions.html : DataGrid Actions
_list_header.html : DataGrid Header Actions(Create, Search)
_list_column_headings.html : DataGrid Sort Action
_add_existing_form.html : many-to-many, add link
config.nested.shallow_delete : delete many-to-many link
true or false(default)
config.list.empty_field_text(default:”-”) : display text if field is nil
you can use "none" or other text.
分享到:
相关推荐
微信小程序 小工具类 XCX-scaffold-master (源代码+截图)微信小程序 小工具类 XCX-scaffold-master (源代码+截图)微信小程序 小工具类 XCX-scaffold-master (源代码+截图)微信小程序 小工具类 XCX-scaffold-...
python库,解压后可用。 资源全名:lk_qtquick_scaffold-1.1.0-py3-none-any.whl
(微信小程序毕业设计)XCX-scaffold-master(源码+截图)(微信小程序毕业设计)XCX-scaffold-master(源码+截图)(微信小程序毕业设计)XCX-scaffold-master(源码+截图)(微信小程序毕业设计)XCX-scaffold-master(源码+截图)...
微信小程序——[小工具类]XCX-scaffold-master(截图+源码).zip 微信小程序——[小工具类]XCX-scaffold-master(截图+源码).zip 微信小程序——[小工具类]XCX-scaffold-master(截图+源码).zip 微信小程序——[小...
npm install -g scaffold-react-component 用法 要获得完整的指导,请执行以下操作: scaffold --help 为了支撑功能性的React组件,请使用,例如 scaffold Modal 要--type ES6类React组件,请使用第二个参数或-...
XCX-scaffold-master.zip小程序精选源码
资源来自pypi官网,解压后可用。 资源全名:dr_scaffold-1.4.3-py3-none-any.whl
资源来自pypi官网。 资源全名:donjon_scaffold-0.7.7-py3-none-any.whl
资源来自pypi官网。 资源全名:lk_qtquick_scaffold-1.1.0-py3-none-any.whl
Rails 的 React 脚手架应用程序 演示: : 许可证:麻省理工学院
资源分类:Python库 所属语言:Python 资源全名:ploomber_scaffold-0.2.6-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:dbbs_scaffold-2.1-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:tracardi_scaffold-1.1-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:donjon_scaffold-0.7.5-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:django3scaffold-0.9.6-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
Laravel开发-laravel-scaffold-admin 为管理CRUD生成脚手架的命令。