lib/hanami/helpers/form_helper.rb in hanami-helpers-1.0.0.beta1 vs lib/hanami/helpers/form_helper.rb in hanami-helpers-1.0.0.beta2

- old
+ new

@@ -72,13 +72,12 @@ # text_field :title # end # end # end # - # # Corresponding template: - # # - # # <%= my_form %> + # <!-- use this in the template --> + # <%= my_form %> module FormHelper # Default HTTP method for form # # @since 0.2.0 # @api private @@ -179,26 +178,27 @@ # # submit 'Update' # end # %> # - # # It will render: - # # - # # <form action="/deliveries/1" method="POST" accept-charset="utf-8"> - # # <input type="hidden" name="_method" value="PATCH"> - # # - # # # Value taken from delivery.delivered_on - # # <input type="date" name="delivery[delivered_on]" id="delivery-delivered-on" value="2015-05-27"> - # # - # # # Value taken from customer.name - # # <input type="text" name="delivery[customer][name]" id="delivery-customer-name" value="Luca"> - # # - # # # Value taken from customer.address.city - # # <input type="text" name="delivery[customer][address][city]" id="delivery-customer-address-city" value="Rome"> - # # - # # <button type="submit">Update</button> - # # </form> + # <!-- output --> + # + # <form action="/deliveries/1" method="POST" accept-charset="utf-8"> + # <input type="hidden" name="_method" value="PATCH"> + # <input type="hidden" name="_csrf_token" value="920cd5bfaecc6e58368950e790f2f7b4e5561eeeab230aa1b7de1b1f40ea7d5d"> + # + # # Value taken from delivery.delivered_on + # <input type="date" name="delivery[delivered_on]" id="delivery-delivered-on" value="2015-05-27"> + # + # # Value taken from customer.name + # <input type="text" name="delivery[customer][name]" id="delivery-customer-name" value="Luca"> + # + # # Value taken from customer.address.city + # <input type="text" name="delivery[customer][address][city]" id="delivery-customer-address-city" value="Rome"> + # + # <button type="submit">Update</button> + # </form> def initialize(name, url, values = {}, attributes = {}) @name = name @url = url @values = values @attributes = attributes || {} @@ -253,22 +253,24 @@ # # submit 'Create' # end # %> # - # Output: - # # <form action="/books" method="POST" accept-charset="utf-8" id="book-form" class="form-horizontal"> - # # <div> - # # <label for="book-title">Title</label> - # # <input type="text" name="book[title]" id="book-title" value="Test Driven Development"> - # # </div> - # # - # # <button type="submit">Create</button> - # # </form> + # <!-- output --> # + # <form action="/books" method="POST" accept-charset="utf-8" id="book-form" class="form-horizontal"> + # <input type="hidden" name="_csrf_token" value="920cd5bfaecc6e58368950e790f2f7b4e5561eeeab230aa1b7de1b1f40ea7d5d"> + # <div> + # <label for="book-title">Title</label> + # <input type="text" name="book[title]" id="book-title" value="Test Driven Development"> + # </div> # + # <button type="submit">Create</button> + # </form> # + # + # # @example Use In A View # # module Web::Views::Books # class New # @@ -282,22 +284,25 @@ # submit 'Create' # end # end # end # + # <!-- in the corresponding template use this --> # <%= form %> # - # Output: - # # <form action="/books" method="POST" accept-charset="utf-8" id="book-form" class="form-horizontal"> - # # <div> - # # <label for="book-title">Title</label> - # # <input type="text" name="book[title]" id="book-title" value="Test Driven Development"> - # # </div> - # # - # # <button type="submit">Create</button> - # # </form> + # <!-- output --> # + # <form action="/books" method="POST" accept-charset="utf-8" id="book-form" class="form-horizontal"> + # <input type="hidden" name="_csrf_token" value="920cd5bfaecc6e58368950e790f2f7b4e5561eeeab230aa1b7de1b1f40ea7d5d"> + # <div> + # <label for="book-title">Title</label> + # <input type="text" name="book[title]" id="book-title" value="Test Driven Development"> + # </div> + # + # <button type="submit">Create</button> + # </form> + # # @example Share Code Between Views # # # Given the following views to create and update a resource # module Web::Views::Books # class New @@ -346,37 +351,41 @@ # # submit submit_label # end # %> # - # Output: - # # <form action="/books" method="POST" accept-charset="utf-8" id="book-form" class="form-horizontal"> - # # <div> - # # <label for="book-title">Title</label> - # # <input type="text" name="book[title]" id="book-title" value="Test Driven Development"> - # # </div> - # # - # # <button type="submit">Create</button> - # # </form> + # <!-- output --> # + # <form action="/books" method="POST" accept-charset="utf-8" id="book-form" class="form-horizontal"> + # <input type="hidden" name="_csrf_token" value="920cd5bfaecc6e58368950e790f2f7b4e5561eeeab230aa1b7de1b1f40ea7d5d"> + # <div> + # <label for="book-title">Title</label> + # <input type="text" name="book[title]" id="book-title" value="Test Driven Development"> + # </div> + # + # <button type="submit">Create</button> + # </form> + # # @example Method override # <%= # form_for :book, routes.book_path(id: book.id), method: :put do # text_field :title # # submit 'Update' # end # %> # - # Output: - # # <form action="/books/23" accept-charset="utf-8" id="book-form" method="POST"> - # # <input type="hidden" name="_method" value="PUT"> - # # <input type="text" name="book[title]" id="book-title" value="Test Driven Development"> - # # - # # <button type="submit">Update</button> - # # </form> + # <!-- output --> # + # <form action="/books/23" accept-charset="utf-8" id="book-form" method="POST"> + # <input type="hidden" name="_method" value="PUT"> + # <input type="hidden" name="_csrf_token" value="920cd5bfaecc6e58368950e790f2f7b4e5561eeeab230aa1b7de1b1f40ea7d5d"> + # <input type="text" name="book[title]" id="book-title" value="Test Driven Development"> + # + # <button type="submit">Update</button> + # </form> + # # @example Nested fields # <%= # form_for :delivery, routes.deliveries_path do # text_field :customer_name # @@ -386,16 +395,18 @@ # # submit 'Create' # end # %> # - # Output: - # # <form action="/deliveries" accept-charset="utf-8" id="delivery-form" method="POST"> - # # <input type="text" name="delivery[customer_name]" id="delivery-customer-name" value=""> - # # <input type="text" name="delivery[address][city]" id="delivery-address-city" value=""> - # # - # # <button type="submit">Create</button> - # # </form> + # <!-- output --> + # + # <form action="/deliveries" accept-charset="utf-8" id="delivery-form" method="POST"> + # <input type="hidden" name="_csrf_token" value="920cd5bfaecc6e58368950e790f2f7b4e5561eeeab230aa1b7de1b1f40ea7d5d"> + # <input type="text" name="delivery[customer_name]" id="delivery-customer-name" value=""> + # <input type="text" name="delivery[address][city]" id="delivery-address-city" value=""> + # + # <button type="submit">Create</button> + # </form> def form_for(name, url, options = {}, &blk) form = if name.is_a?(Form) options = url name else