Adding a custom select to omniauth register form

Hi,

I'm creating a rails app using omniauth 1.0.1 on Rails 3.1.3 and ruby
1.9.2

I'm having trouble adding a select field that populates from a class
constant in my user model.

Here's my model:

class User < ActiveRecord::Base
  ROLES = ["Customer","Service Supplier"]

  has_many :leads

  validates_presence_of :role

  def self.from_omniauth(auth)
     ...
  end

  def self.create_with_omniauth(auth)
     ...
  end

end

Here's a snippet of my view from identities/new.html.erb:

<%= form_tag "/auth/identity/register" do %>

<div class="field">
  <%= label_tag :role %><br>
  <%= select :user, :role, User::ROLES %>
</div>

When I try and test the registration process I get the error message:

Validation failed: Role can't be blank

The parameters are:
{"utf8"=>"✓",
"authenticity_token"=>"sSWArZADlbD1V9sUQGfP2pSsJSEOsIhu865mjdvI9to=",
"name"=>"asdfasfd",
"email"=>"1234123412341234",
"user"=>{"role"=>"Customer"},
"password"=>"[FILTERED]",
"password_confirmation"=>"[FILTERED]",
"commit"=>"Register",

Can anyone suggest some changes in my code to allow the role to set in
the user model from the omniauth registration form?

Many thanks.

Hi,

I'm creating a rails app using omniauth 1.0.1 on Rails 3.1.3 and ruby
1.9.2

I'm having trouble adding a select field that populates from a class
constant in my user model.

Here's my model:

class User < ActiveRecord::Base
ROLES = ["Customer","Service Supplier"]

has_many :leads

validates_presence_of :role

def self.from_omniauth(auth)
    ...
end

def self.create_with_omniauth(auth)
    ...
end

end

Here's a snippet of my view from identities/new.html.erb:

<%= form_tag "/auth/identity/register" do %>

<div class="field">
<%= label_tag :role %><br>
<%= select :user, :role, User::ROLES %>
</div>

What do the fields that send the omniauth credentials look like? I'm betting that the role attribute isn't included in the same group of parameters.

Walter

Hi Walter,

Thanks for the email.

I forgot to mention that despite the error the user and identity are
created. Just that the role field is blank in the database and you get
the error I mentioned in my email.

I'm not 100% sure how to display the fields that send the omniauth
credentials - so I can answer your question.

If you can help with this that would be great - I'll do some googling
in the meantime.

Cheers.

Hi Walter,

Thanks for the email.

I forgot to mention that despite the error the user and identity are
created. Just that the role field is blank in the database and you get
the error I mentioned in my email.

I'm not 100% sure how to display the fields that send the omniauth
credentials - so I can answer your question.

Well, look in the view file for that form, and see what you see there. If you're creating the select field, you must be adding it to the same view file that contains the rest of the form, otherwise you wouldn't see it.

Walter

Hi Walter,

Thanks again.

I've replied directly to your google groups registered email address
wa...@wdstudio.com.

I thought it might be more appropriate.

Let me know if you get that ok or if you prefer me to continue using
the google group.

Cheers.