Sha256: 571764671fddc2c117229f9a366f505cb4881a9c68b9ae99ba0b467f11516dac

Contents?: true

Size: 1.25 KB

Versions: 6

Compression:

Stored size: 1.25 KB

Contents

= FunkyForm
The purpose of form objects is to take user-entered data and perform work on it.

== Installation
Add to your Gemfile
  gem "funky_form"

== Examples

==== app/models/post.rb
  class Post < ActiveRecord::Base
  end

==== app/forms/post_form.rb
  class PostForm
    include FunkyForm

    model Post

    attribute :id, Integer
    attribute :title, String
    attribute :body, String

    validates :title, :presence => true, :length => {:maximum => 30}
    validates :body, :presence => true, :length => {:within => 10..30}
  end

==== app/controllers/posts_controller.rb
  class PostsController < ApplicationController
    def new
      @post_form = PostForm.new
    end

    def create
      @post_form = PostForm.new(params[:post])

      if @post_form.valid?
        Post.create(@post_form.attributes)
        flash[:notice] = "Successfully created"
        redirect_to :posts
      else
        flash[:alert] = "Validation errors"
        render "new"
      end
    end
  end

==== app/views/posts/new.html.erb
  <h1>New Post</h1>
  <%= form_for @post_form do |f| %>
    <p>
      <%= f.label :title %>
      <%= f.text_field :title %>
    </p>

    <p>
      <%= f.label :body %>
      <%= f.text_area :body %>
    </p>

    <p><%= f.submit %></p>
  <% end %>

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
funky_form-0.2.1 README.rdoc
funky_form-0.2.0 README.rdoc
funky_form-0.1.3 README.rdoc
funky_form-0.1.2 README.rdoc
funky_form-0.1.1 README.rdoc
funky_form-0.1.0 README.rdoc