`
CaiDeHen
  • 浏览: 96904 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

#16 Virtual Attributes

F# 
阅读更多
Keep your controllers clean and forms flexible by adding virtual attributes to your model. This very powerful technique allows you to create form fields which may not directly relate to the database.


<!-- users/new.rhtml -->
<%= f.text_field :full_name %>


# models/user.rb
def full_name
  [first_name, last_name].join(' ')
end

def full_name=(name)
  split = name.split(' ', 2)
  self.first_name = split.first
  self.last_name = split.last
end


分享到:
评论

相关推荐

    serialize_virtual_attributes:用哈希序列化虚拟属性

    gem 'serialize_virtual_attributes' 然后执行: $ bundle 或将其自己安装为: $ gem install serialize_virtual_attributes 用法 class Person &lt; ActiveRecord :: Base serialize :fullname , Hash ...

    前端开源库-virtual-hyperscript-svg

    它的基本语法是`h('tagname', attributes, [children])`。例如,用hyperscript创建一个SVG矩形可以写成`h('rect', {x: 0, y: 0, width: 100, height: 100})`。这种语法直观易懂,适合于动态生成和操作DOM。 ...

    VC++ 画线 cdc

    // Attributes public: CRandDrawDoc* GetDocument(); // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CRandDrawView) public: virtual void ...

    深入java虚拟机(inside the java virtual machine)

    16 Control Flow Conditional Branching Unconditional Branching Conditional Branching with Tables Saying Tomato: A Simulation On the CD-ROM The Resources Page 17 Exceptions Throwing and Catching ...

    VC++ CTabCtrlBar 多标签

    // Attributes public: // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CMainFrame) virtual BOOL PreCreateWindow(CREATESTRUCT& cs); //}}AFX_...

    南自104规约实现(源代码)

    // Attributes public: // Operations public: CClientSocket(); virtual ~CClientSocket(); // Overrides public: // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CClientSocket) ...

    stdafx.h代码

    stdafx.h的代码// This is a part of the Microsoft Foundation Classes C++ library. ...// All rights reserved. // // This source code is only intended as a supplement to the // Microsoft Foundation Classes ...

    CSharp详细说明书

    - **Virtual, Override, and Abstract Methods**: 虚方法可以在派生类中被重写;抽象方法在基类中声明但没有实现,必须在派生类中实现;重写方法是指派生类中提供了对基类虚方法的具体实现。 - **Method ...

    linux 编程 函数接口锦集 (N-Z)

    #### X - Extended Attributes - **`getxattr`**:获取文件扩展属性。 - **`setxattr`**:设置文件扩展属性。 #### Y - Miscellaneous - **`y0`**、**`y1`**、**`yn`**:Bessel 函数。 #### Z - Compression and...

    图像处理图像灰度增强

    // Attributes public: CDC m_MemDCMap; UINT m_DataX,m_DataY; // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CFigure) protected: virtual ...

    小型绘图系统

    // Attributes public: // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CHomework2Doc) public: virtual BOOL OnNewDocument(); virtual void ...

    vc++ 学生电子档案

    // Attributes public: // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CMainFrame) virtual BOOL PreCreateWindow(CREATESTRUCT& cs); //}}AFX_...

    A Secure Sharing Mechanism for Data Resources in Extended Virtual Machine System

    With the growth of the requirement of users, it becomes a challenge that how to ensure the security of data resources sharing in extended virtual machine system. In order to solve this problem, we ...

    Vue.js 2.0窥探之Virtual DOM到底是什么?

    attributes: { id: 'myId' }, children: [...] }; ``` 当需要更新时,开发者可以先在虚拟DOM上进行操作,如`domNode.children.push('&lt;ul&gt;Item 3&lt;/ul&gt;');`,然后再通过高效的算法(如Diff算法)将这些变化同步到...

    Oracle Database 10g: The Top 20 Features for DBAs

    **Description:** VPD enhances security by dynamically restricting access to data based on user attributes or session characteristics. It ensures that users only see data they are authorized to access....

    提高C#编程水平的50个要点

    #### 16. 尽量避免产生资源垃圾 合理管理资源,避免不必要的内存占用。 #### 17. 尽量避免使用装箱(boxing)和拆箱(unboxing) 装箱和拆箱会导致性能开销,尤其是在循环中。 ```csharp List&lt;int&gt; numbers = new List...

    简易浏览器的实现(myweb2.0)

    // Attributes public: void OnNew(); void SetPage(LPCTSTR lpszURL); // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CMainFrame) virtual ...

    MFC多线程编程.pdf

    - **lpThreadAttributes**:指向SECURITY_ATTRIBUTES结构的指针,用于设置线程的安全属性,默认可设为NULL。 - **dwStackSize**:指定线程堆栈的大小,默认为0,表示使用默认大小。 - **lpStartAddress**:线程开始...

    CTrueColorToolBar 类

    // Attributes private: BOOL m_bDropDown; struct stDropDownInfo { public: UINT uButtonID; UINT uMenuID; CWnd* pParent; }; CArray , stDropDownInfo&&gt; m_lstDropDownButton; // Operations ...

    MFC对多线程编程的支持

    - `virtual BOOL CWinThread::InitInstance();` - 重载此函数以控制用户界面线程实例的初始化。 - 可以在这个函数中设置线程所需的资源或者初始化线程的状态。 #### 四、线程生命周期 MFC中的线程在其生命周期中...

Global site tag (gtag.js) - Google Analytics