Skip to content

Instantly share code, notes, and snippets.

@jacquescrocker
Created April 2, 2010 08:46
Show Gist options
  • Save jacquescrocker/352936 to your computer and use it in GitHub Desktop.
Save jacquescrocker/352936 to your computer and use it in GitHub Desktop.
ActiveParams (working title)
# app/params/edit_account_params.rb
class EditAccountParams < ActiveParams::Base
attributes :first_name,
:last_name,
:email,
:password
validates_presence_of :first_name, :last_name
has_many :addresses do
attributes :address1,
:city,
:state,
:zip
end
end
# app/params/signup_params.rb
class SignupParams < ActiveParams::Base
attributes :first_name,
:last_name,
:email,
:password
has_many :addresses do
attributes :street,
:city,
:state,
:zip
validates_presence_of :street
end
has_one :job do
attribute :company
attribute :title
end
validates_confirmation_of :password
end
class UsersController < ApplicationController
def new
@signup = SignupParams.new(params)
end
def create
@signup = SignupParams.new(params)
if @signup.save
redirect_to @signup
else
render :new
end
end
def edit
# model_for can also use send(:attribute) on all the passed in objects to initialize a named parameter set
@edit_form = EditAccountParams.new(User.find(params[:id]))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment