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

#74 Complex Forms Part 2

阅读更多
See how to use Javascript and RJS to add and remove form fields dynamically. This episode will build upon the previous episode allowing you to create any number of tasks in one form the same time a project is created.
<!-- layouts/application.rhtml -->
<%= javascript_include_tag :defaults %>

<!-- projects/new.rhtml -->
<div id="tasks">
  <%= render :partial => 'task', :collection => @project.tasks %>
</div>
<p><%= add_task_link "Add a task" %></p>

<!-- projects/_task.rhtml -->
<div class="task">
<% fields_for "project[task_attributes][]", task do |task_form| %>
  <p>
    Task: <%= task_form.text_field :name %>
    <%= link_to_function "remove", "$(this).up('.task').remove()" %>
  </p>
<% end %>
</div>
# projects_helper.rb
def add_task_link(name)
  link_to_function name do |page|
    page.insert_html :bottom, :tasks, :partial => 'task', :object => Task.new
  end
end
分享到:
评论

相关推荐

    PROFESSIONAL F# 2.0

    - **Lexical Structure (Chapter 2):** This chapter covers the lexical structure of F#, including identifiers, keywords, operators, and comments. It lays the groundwork for understanding how code is ...

    sympy-docs-pdf-1.0.pdf

    The printing system is a crucial part of SymPy. It allows users to format expressions in various styles, such as LaTeX, MathML, and plain text. ##### 5.18 Plotting Module Visualization is an ...

    Cours-VB-NET-2010-Developpez-com

    The course follows a structured approach, starting with fundamental concepts and gradually moving towards more complex topics. The sequence ensures that learners build a solid foundation before ...

    modeling algorithm

    It provides a visual programming interface that simplifies the process of creating complex forms and structures through a series of connected components and parameters. The tool is primarily used in ...

    考研英语单词

    - **例句**:Social media has become an integral part of our daily lives. ##### 2. Rate 速率,比率,等级,价格,费用,估价 - **应用场景**:统计学、经济学等。 - **例句**:The unemployment rate is ...

    GWT in Action

    It provides a comprehensive set of tools and libraries that facilitate the creation of complex user interfaces and robust back-end services. **GWT in Action** is a comprehensive guide that covers all...

    软件开发技术基础:第一章 C#.NET程序设计基础3.ppt

    复数由实部(real part)和虚部(imaginary part)组成。在C#中,我们通过定义私有成员变量`re`和`im`来存储这两个部分。在类的声明中,我们有以下代码: ```csharp class Complex { private double re, im; ``` ...

    Pattern Recogintion and Machine Learning

    The book is part of the *Information Science and Statistics* series, edited by notable figures such as M. Jordan, J. Kleinberg, and B. Schölkopf. ### Key Knowledge Points #### 1. **Overview of ...

    Advanced Engineering Mathematics

    2 Vectors and Vector Spaces 55 CHAPTER 2.1 Vectors, Geometry, and Algebra 56 2.2 The Dot Product (Scalar Product) 70 2.3 The Cross Product (Vector Product) 77 2.4 Linear Dependence and Independence of...

    Machine Learning for Audio, Image and Video Analysis 2nd

    The third part Applications shows how the abstract problems defined in the second part underlie technologies capable to perform complex tasks such as the recognition of hand gestures or the ...

    Beginning PHP 5.3

    - **Complex Queries:** Techniques for building complex queries, including joins and subqueries. **Chapter 15: Making Your Job Easier with PEAR** - **PEAR Overview:** Explanation of what PEAR ...

    Quick Time File Format

    QTFF also supports interactive features, enabling the creation of multimedia content with clickable links, forms, and other interactive elements. This feature is particularly useful for educational ...

    Pro AngularJS

    Part 2 – Working with AngularJS 9. The Anatomy of an AngularJS App 10. Using Binding and Template Directives 11. Using Element and Event Directives 12. Working with Forms 13. Using Controllers and ...

    Practical Machine Learning with Python(pdf书+sourcecode)

    Part 2 details standard machine learning pipelines, with an emphasis on data processing analysis, feature engineering, and modeling. You will learn how to process, wrangle, summarize and visualize ...

Global site tag (gtag.js) - Google Analytics