Ruby/Rails/Form
Материал из Wiki.crossplatform.ru
Access form data from controller
<A href="http://www.crossplatform.ru/Code/RubyDownload/accesFormDataFromController.zip">accesFormDataFromController.zip( 92 k)</a>
1. <A href="FormData.htm">Form Data</a> <A href="FormData.htm"></a>
Form Data
File: hello_controller.rb class HelloController < ApplicationController def showform end def show_formdata @name = params[:name] @prog_languages = params[:prog_languages] || [] @operating_systems = params[:operating_systems] || [] end end File: show_formdata.rhtml <h2>Display Posted Form Data</h2> Name: <%= @name %> <br /> Programming Languages: <%= @prog_languages.join(", ") %> <br /> Operating Systems: <%= @operating_systems.join(", ") %> <br /> <p> YAML Output from Debug: <br /> <%= debug(params) %> </p> File: showform.rhtml <h2>A Simple Form</h2> <%= form_tag(:action => "show_formdata") %> <p>Text Field: <%= text_field_tag("name","Aneesha") %></p> <p>Drop-down Selection Box: <% languages = ["Ruby", "Java", "C#"].map do |lang| "<option>#{lang}</option>" end.to_s %> <%= select_tag("prog_languages[]", languages, :multiple => "true") %></p> <p>Checkboxes: <%= check_box_tag("operating_systems[]","Windows") %> Windows <%= check_box_tag("operating_systems[]","Linux") %> Linux <%= check_box_tag("operating_systems[]","Mac") %> Mac </p> <%= submit_tag("Submit Form") %> <%= form_tag %>
<A href="http://www.crossplatform.ru/Code/RubyDownload/getSetFormDataWithFormTag.zip">getSetFormDataWithFormTag.zip( 91 k)</a>