Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8130913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:54:27+00:00 2026-06-06T08:54:27+00:00

Hello again, stackoverflow community! I’m working on writing a simple blog system in Rails,

  • 0

Hello again, stackoverflow community!

I’m working on writing a simple blog system in Rails, and I’m using Devise for the authentication part.

I got the basic email/password registration going, and now I’ve set up a one-to-one connection of the users table (the basic one generated by devise) and a UserData table, containing things such as username, permissions, about, and so on.

It’s pretty easy – the user table is 100% devise vanilla, and has_one UserData.
Userdata belongs_to a user.

I tried expanding the sign up form generated by Devise, so that it would allow a user to enter, not just his e-mail and password, but also his desired user name.
That way, when the form would be sent, if the names of the form fields would be correct (the right structure of nested hashes, such as "email" for the user’s email, and "UserData[name]" for the user’s desired name), the new user would be created automatically, and the proper corresponding UserData entry should also be created automatically by Rails, correct?

Right now, I’m having a huge issue with the UserData[name] field not appearing at all…
Here’s the file I’m having trouble with…

new.html.erb

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>

  <div><%= f.label :email %><br />
<%= f.email_field :email %></div>


#This is the tidbit that doesn't work
<%= f.fields_for "UserData" do |ud_f| %>
  <%= ud_f.label "username" %>
  <%= ud_f.text_field :name %>
<% end %>

  <div><%= f.label :password %><br />
  <%= f.password_field :password %></div>

<div><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></div>

<div><%= f.submit "Sign up" %></div>
<% end %>

<%= render :partial => "devise/shared/links" %>

I have been searching for an answer for hours and hours, but to no avail. If I purposely misspell the word "UserData" in the fields_for block, it prints out the field. This is strange, and I have no idea what’s making that field disappear…

I’d really appreciate a little bit of help!
Thanks for your time! 🙂

edit 1+2:

After a few messing around, I’ve overridden devise’s default registration controller and created my own. I’ve edited the devise route to call my custom controller as timbrandes suggested, but I can’t seem to access @user in my controller. Here’s the code I have so far…

class RegistrationsController < Devise::RegistrationsController
  def new
   resource = build_resource({})
   resource.UserData = UserData.new
   respond_with resource
  end

  def create
    logger.debug "\n\n\nIN CREATE\n\n\n\n"
    logger.debug params.to_json
    super
  end

  def update
    super
  end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T08:54:28+00:00Added an answer on June 6, 2026 at 8:54 am

    Well, a lot of time has passed, but I eventually got it working by scrapping and re-doing most of my Devise code. To be honest, it wasn’t that much to re-write, and now it works great.

    For any future developers browsing this (slightly confusing) question and answer, the only advice I can give you is to make sure to write structured form code, especially for nested resources. This is my current registrations_controller.rb that works:

    class RegistrationsController < Devise::RegistrationsController
      def new
        resource = build_resource({})
        resource.build_user_data
        respond_with resource
      end
    
      def create
        resource = build_resource(params[:user])
    
        if(resource.save)
          sign_in(resource_name, resource)
          respond_with resource, :location => after_sign_up_path_for(resource)
        else
          render :action => "new"
        end
    
    
      end
    
      def update
        super
      end
    end 
    

    And the .erb for the registration form:

    <div class="form-box">  
    
        <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
          <%= devise_error_messages! %>
    
          <div><%= f.label :email %>
          <%= f.email_field :email %></div>
    
            <%= f.fields_for(:user_data)  do |udf| %>
              <%= udf.label :name, "Desired user name" %>
              <%= udf.text_field :name %>
    
              <%= udf.label :roles, "Privileges"%>
              <% for role in UserData::ROLES %>
                   <%= check_box_tag "user[user_data_attributes][roles][]" , role, resource.user_data.roles.include?(role) %>
                   <%=h role.humanize %><br />
              <% end %>
              <%= hidden_field_tag "user[user_data_attributes][roles][]" %>
    
            <% end %>
    
          <div><%= f.label :password %>
          <%= f.password_field :password %></div>
    
          <div><%= f.label :password_confirmation %>
          <%= f.password_field :password_confirmation %></div>
    
          <div><%= f.submit "Sign up" %></div>
        <% end %>
    
        <%= render :partial => "devise/shared/links" %>
    
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello again Stackoverflow community, Today I am trying to execute an application with commandline
Hello again Stackoverflow people! Assume I have these words: smartphones, smartphone I want to
Hello once again stackoverflow folks, this is really hard and it's been torturing my
hello again, WSO2 community. My last question about your architecture for my research is
Hello again stackoverflow... Once again I have a troublesome problem. I have a page
Hello again great knowledge masters of stackoverflow, once again the small coder apprentice tabaluga
Hello stackoverflow pals.I am a new rails learner. My question is: I am listing
Hello again stackoverflow, I have a question concerning List of Objects. I have tried
Hello again stackoverflow! So i build this script: <?php $xmlurl = 'http://api.ipinfodb.com/v2/ip_query.php?key=apikey&ip=127.0.0.100&timezone=false'; $xml =
Hello wonderful people of stackoverflow! I have a problem. I am working on an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.