Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

formup

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

formup

  • 1.0.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Formup

Build Status

Formup is rubygem for creating data model based form class. Formup use activemodel gem.(>= 3.2.0) You can get the benefits of ActiveModel. ex) validations, application to form_for etc.

Installation

Add this line to your application's Gemfile:

gem 'formup'

And then execute:

$ bundle

Or install it yourself as:

$ gem install formup

Usage

Include Formup to your class.

class SalesForm
  include Formup

  # define attributes (sales_id, sales_price, sales_tax)
  source :sales, :attributes => [:id, :price, :tax]
  # define attributes (customer_id, customer_name, contact)
  source :customer, :attributes => [:id, :name], :aliases => { :email => :contact }

  attr_accessor :items

  # Handle hash parameters that were not processed in initialize method.
  def handle_extra_params(params)
    self.items = {}
    params.each do |k, v|
      self.items[v] = params[k.to_s.gsub(/^code/, "count")] if k.to_s.match(/^code/)
    end
  end
end

Initialize with hash parameters.(like ActiveRecord)

# params => { :sales_id => 1, :sales_price => 1000, ... }
form = SalesForm.new(params)

Load from hash and data model that have some accessor methods.

form = SalesForm.new
sales = Sales.find(1)
form.load(:sales => sales, :customer => { :id => 1, :name => "John Doe", :email => "john@example.com"})

Get parameters for data model by params_for method.

form = SalesForm.new(params)
sales = Sales.new(form.params_for(:sales))
sales.save

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

FAQs

Package last updated on 17 Oct 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc