Created
April 2, 2010 08:46
-
-
Save jacquescrocker/352936 to your computer and use it in GitHub Desktop.
ActiveParams (working title)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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