Ability to pass parameters to the registrations#sign_in

34 views
Skip to first unread message

KandadaBoggu

unread,
Oct 30, 2012, 12:53:32 PM10/30/12
to plataforma...@googlegroups.com

Once in a while we send customized registration links to our leads. The link contains parameters than can be used to pre-fill the registration form.

http://www.example.com/users/sign_up?user[company_name]=Foo&user[region]=NA

Our registration form has fields for accepting company name and region. Which can be pre-filled based on the registration link.

This should work in practice, but it doesn't due to how the registrations#new action is implemented. The new action calls the build_resource method with an empty hash.

def new
  resource = build_resource({})
  respond_with resource
end

The build_resource method ignores the resource_params when the input is non nil.

def build_resource(hash=nil)
  hash ||= resource_params || {}
  self.resource = resource_class.new_with_session(hash, session)
end  

I had to over-ride the the new action in my registrations controller to overcome this issue. I don't like my solution as it is brittle.

def new
  resource = build_resource
  respond_with resource
end

Is there a reason why the new action is invoked with an empty hash? Can it be invoked with out empty hash(like in the create action)?

Reply all
Reply to author
Forward
0 new messages