ruby - Rails 4: having a proxy model to combine multiple models -
i trying hand on rails (4). have done sinatra earlier.
i have signup form, in user can fill out organization name, address , own name, password etc. have 2 tables - users , organizations, table populated signup data. so, have 2 active records model users
, organizations
. controllers looks follows:
class signupscontroller < applicationcontroller # /signup def new # show html form end # post /signup def create @signup = registration.register(signup_params) respond_to |format| if @signup.save format.html { redirect_to @signup, notice: 'signup created.' } else format.html { render action: 'new' } end end end private # never trust parameters scary internet, allow white list through. def signup_params params[:signup] end end
i not have registration
model (table in db). looking such registration
model (should call model?) can have like:
class registration def self.register params o = organization.new params u = user.new o.id, params self.send_welcome_email params[:email] end def send_welcome_email email #send email here end end
1) should keep registration
class?
2) correct approach such situation? if not, best way it?
3) having such class effect running unit tests?
4) see there file, signup_helper.rb
use of in signupscontroller
you can include activemodel::model
in model, , behave normal model. able validations, callbacks. other persisting database.
have @ this more info.
Comments
Post a Comment