All threads / One form, two separate controllers, created at once.

Ask A Question


You’re not receiving notifications from this thread.

One form, two separate controllers, created at once.

Masud Hossain asked in Rails

I'm trying to create a sign_up form where the user will choose his email + password AND and Article at the same time as creating a user account.

So assentially, one form will create a new User and it will also create a new Article.

This is my new user form

<%= form_for(@user, url: registrations_path) do |f| %>

        <%= f.email_field :email %>

        <%= f.password_field :password %>

        <%= f.password_field :password_confirmation %>

        <%= submit_tag "Sign up", :class => "signupsubmit" %>

<%  end %>

And my new article form

<%= form_for(@article) do |f| %>

    <%= f.text_field :url  %>

    <%= f.submit "Submit"  %>

<% end %>

Essentially i want to combine these two forms into ONE.

you can use association between article and user and use nested attributes in it.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 53,130+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2021 GoRails, LLC. All rights reserved.