`
myrev
  • 浏览: 164047 次
  • 性别: Icon_minigender_1
  • 来自: 福建
社区版块
存档分类
最新评论

Active Scaffold Note -- Rails Plugin

阅读更多
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-master (源代码+截图)微信小程序 小工具类 XCX-scaffold-...

    Python库 | lk_qtquick_scaffold-1.1.0-py3-none-any.whl

    《Python库lk_qtquick_scaffold-1.1.0-py3-none-any.whl的深度解析》 在Python的世界里,丰富的库是其强大功能的重要支撑。今天我们要探讨的是名为"lk_qtquick_scaffold"的Python库,版本号为1.1.0,以whl格式提供...

    agile-web-development-with-rails_2

    - **Rails脚手架(Scaffold):** 自动生成基本的应用程序代码,包括模型、视图、控制器等,大大加快了开发速度。 - **Rails测试框架:** 提供了完整的测试解决方案,包括单元测试、集成测试和系统测试,确保应用程序...

    (微信小程序毕业设计)XCX-scaffold-master(源码+截图).zip

    (微信小程序毕业设计)XCX-scaffold-master(源码+截图)(微信小程序毕业设计)XCX-scaffold-master(源码+截图)(微信小程序毕业设计)XCX-scaffold-master(源码+截图)(微信小程序毕业设计)XCX-scaffold-master(源码+截图)...

    Laravel开发-laravel-scaffold-admin

    在本文中,我们将深入探讨Laravel开发中的一个重要概念——`laravel-scaffold-admin`,它是一种用于快速构建管理界面的工具,特别适用于执行常见的CRUD(创建、读取、更新和删除)操作。Laravel是一个优雅且强大的...

    rails-scaffold-react:Rails 的 React 脚手架应用程序

    "rails-scaffold-react" 是一个基于 Ruby on Rails 的应用程序模板,专为集成 React.js 前端库而设计。这个脚手架可以帮助开发者快速搭建一个包含 Rails 后端和 React 前端的完整Web应用。它利用了 Rails 的强大功能...

    微信小程序——[小工具类]XCX-scaffold-master(截图+源码).zip

    微信小程序——[小工具类]XCX-scaffold-master(截图+源码).zip 微信小程序——[小工具类]XCX-scaffold-master(截图+源码).zip 微信小程序——[小工具类]XCX-scaffold-master(截图+源码).zip 微信小程序——[小...

    scaffold-react-component:搭建带有样式,测试和故事的React组件

    npm install -g scaffold-react-component 用法 要获得完整的指导,请执行以下操作: scaffold --help 为了支撑功能性的React组件,请使用,例如 scaffold Modal 要--type ES6类React组件,请使用第二个参数或-...

    PyPI 官网下载 | dr_scaffold-1.4.3-py3-none-any.whl

    标题中的"PyPI 官网下载 | dr_scaffold-1.4.3-py3-none-any.whl"指的是一个在Python Package Index (PyPI)官方仓库中发布的软件包。PyPI是Python社区用来分发开源软件的主要平台。`dr_scaffold`是这个包的名字,而`...

    XCX-scaffold-master-html

    【XCX-scaffold-master-html】是一个用于快速搭建微信小程序(XCX)开发环境的模板项目,其中包含了HTML文件,这表明它可能结合了HTML来构建小程序的页面结构。在这个项目中,HTML可能被用作设计和组织小程序界面的...

    XCX-scaffold-master.zip小程序精选源码

    XCX-scaffold-master.zip小程序精选源码

    Laravel开发-scaffold-interface

    【Laravel开发-Scaffold Interface详解】 在 Laravel 开发过程中,Scaffold Interface 是一个非常实用的工具,它能够帮助开发者快速生成基本的CRUD(创建、读取、更新、删除)操作的控制器、视图和模型。这个工具极...

    inspinia admin - v2.5 Rails_Seed_Project

    5. **脚手架生成器**:项目可能还包括了一些脚手架(Scaffold)生成的代码,用于快速创建CRUD操作,提高开发效率。 6. **测试框架**:为了保证代码质量,项目可能会包含Rspec或Minitest等测试框架,鼓励开发者进行...

    Laravel开发-reverse-scaffold-generator

    在Laravel框架中,开发工具和库极大地提高了开发效率,其中"reverse-scaffold-generator"是一个非常实用的工具,尤其对于快速构建 CRUD(创建、读取、更新、删除)操作的应用程序。这个工具允许开发者从现有的数据库...

    PyPI 官网下载 | donjon_scaffold-0.7.7-py3-none-any.whl

    资源来自pypi官网。 资源全名:donjon_scaffold-0.7.7-py3-none-any.whl

    XCX-scaffold-master-微信小程序源码.zip

    【标题】"XCX-scaffold-master-微信小程序源码.zip" 涉及的主要知识点是微信小程序的开发和源码管理。微信小程序是一种轻量级的应用开发平台,它允许开发者在微信内创建和发布功能丰富的应用程序,而无需安装。"XCX-...

    PyPI 官网下载 | lk_qtquick_scaffold-1.1.0-py3-none-any.whl

    资源来自pypi官网。 资源全名:lk_qtquick_scaffold-1.1.0-py3-none-any.whl

    Python库 | ploomber_scaffold-0.2.6-py3-none-any.whl

    资源分类:Python库 所属语言:Python 资源全名:ploomber_scaffold-0.2.6-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

Global site tag (gtag.js) - Google Analytics