0

My apologies if this has been asked before, but I'm not sure about this.

I would like to know if it's possible to use a form in Rails with multiple models.

I know you can do something like this

<%= form_for @users do |f| %>

In the form, I'm trying to create, I need form fields for 2 different models, because I need to use the attributes from the other model.

I was thinking something like this might work

<%= form_for @users, @songs do |f,g| %>

  <%= f.label :username %>
  <%= f.text_field :username %>

  <%= g.label :song %>
  <%= g.text_field :song %>

<% end %>

I believe this will work, but I'm not sure. Is this possible in Rails?

1 Answer 1

1

I think you are looking for rails built-in helper fields_for.

See the docs here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.