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

#57 Create Model Through Text Field

F# 
阅读更多
Let's say you provide a select menu for setting which category a given product belongs to, but you also want the option of creating a new category by typing the name in a text field. See a great way to do that in this episode.
<!-- views/products/_form.rhtml -->
<p>
  <label for="product_category_id">Category:</label><br />
  <%= f.collection_select :category_id, Category.find(:all), :id, :name, :prompt => "Select a Category" %>
  or create one:
  <%= f.text_field :new_category_name %>
</p>
# models/product.rb
belongs_to :category
attr_accessor :new_category_name
before_save :create_category_from_name

def create_category_from_name
  create_category(:name => new_category_name) unless new_category_name.blank?
end
分享到:
评论

相关推荐

    Machine Learning by Tutorials:Beginning machine learning for Apple and iOS.pdf

    Create ML: Learn how to create your own model using Apple’s Create ML Tool. Turi Create and Keras: Learn how to tune parameters to improve your machine learning model using more advanced tools. Image...

    Machine Learning by Tutorials: Beginning machine learning for Apple and_code.zip

    Create ML: Learn how to create your own model using Apple’s Create ML Tool. Turi Create and Keras: Learn how to tune parameters to improve your machine learning model using more advanced tools. Image...

    Machine Learning by Tutorials: Beginning machine learning for Apple and_code.z01

    Create ML: Learn how to create your own model using Apple’s Create ML Tool. Turi Create and Keras: Learn how to tune parameters to improve your machine learning model using more advanced tools. Image...

    Six Step Relational Database Design 2nd Edition

    Step Relational Database DesignTM uses three case studies and starts with a statement of the problem by the client and then goes through the six steps necessary to create a reliable and accurate data ...

    Microsoft SharePoint 2010 Developer Reference

    - **Developing Custom Field Types:** Steps to create custom field types. - **Field Rendering Control:** How to control the display of fields using templates and controls. - **Supporting Mobile Devices...

    google api php client

    // create the datastore service class $datastore = new Google_Service_Datastore($client); // build the query - this maps directly to the JSON $query = new Google_Service_Datastore_Query([ 'kind' =&gt; ...

    雷达技术知识

    20. Marmot Dam: Orthophotographyand Colorized Slope Model 50 21. LiDAR Point Density versus Interpolation 53 LIST OF TABLES T~k p~ 1. Reported Accuracies of 2006 and 2007 LiDAR 24 2. Results of LiDAR ...

    HP笔记本BIOS工具

    To use this system, select your supported hp probook/elitebook model from the dropdown list. The Serial Number field and UUID Filed will populate with data and will need to be changed to that of your ...

    Learning ASP.NET Core MVC Programming

    This book is uniquely designed for developers who are looking to transition their skills into the .NET development field The standalone chapter structure leaves you free to explore ASP.NET MVC to ...

    Proxy Pattern Informatization Research Based On SaaS

    .This model makes it easy to extend the application’s data model to meet all users’ individual needs, and restoring a user’s data from backups in a failure is a relatively simple thing[9].But ...

    django-master-class

    - **Custom Template Tags:** Developers can create their own template tags to perform complex operations or repetitive tasks within templates. - **Tag Registration:** Custom tags must be registered in ...

    hibernate_reference.pdf

    - **Implementing a Naming Strategy**: Explains how to customize the naming strategy used by Hibernate when mapping Java class names to database table names and field names to column names. - **XML ...

    Java邮件开发Fundamentals of the JavaMail API

    further than the JavaMail API, which offers a protocol-independent model for working with IMAP, POP, SMTP, MIME, and all those other Internet-related messaging protocols. With the help of the ...

    基于android平台的大象挪盒子游戏设计与开发-毕业论文.doc

    The study contributes to the growing field of mobile game development, showcasing how Android SDK can be utilized to create innovative and engaging games that not only entertain but also enrich ...

Global site tag (gtag.js) - Google Analytics