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

  • SEARCH
  • Home
  • 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 6014099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:38:35+00:00 2026-05-23T02:38:35+00:00

I have a form to create a new record. I have that partial that

  • 0

I have a form to create a new record.

I have that partial that I’d like to use from the view in different models.

How do i do that? It seems like the controller for the partial form should be reusable as well.

For example, this is what I have. I call this partial both from my view/users/show and view/message/new, and so it seems like I need to create an @message and @contact instance in both the user controller and message controller. Feels not DRY:

= semantic_form_for @message do |f|
  2   #message_form
  3     = f.error_messages
  4     %p
  5       = f.label :account
  6       %br
  7       = f.text_field :account
  8     %p
  9       = f.label :subject
 10       %br
 11       = f.text_field :subject
 12     %p
 13       = f.label :body
 14       %br
 15       = f.text_area :body
 16     = hidden_field_tag :sender_id, params[:sender_id]
 17     = hidden_field_tag :receiver_id, params[:receiver_id]
 18 
 19     = f.submit
 20   #add_contact_btn
 21     = link_to "Add Contact", new_contact_path
 22 
 23     #contact_form
 24       = form_for @contact do |fc|
 25         %p
 26           = fc.label :first_name
 27           %br
 28           = fc.text_field :first_name
 29         %p
 30           = fc.label :last_name
 31           %br
 32           = fc.text_field :last_name
  • 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-05-23T02:38:36+00:00Added an answer on May 23, 2026 at 2:38 am

    Keep the partial in a shared folder and refer to it whenever you need to.

    For example, if you wanted to use the shared/_form.html.{erb,haml} partial, you would write:

    render 'shared/form'
    

    Controllers are not tied to models. You can manage as many as you need in a single controller. They are tied to the views, however, so make sure they are fit for your models.


    If you are just creating a new message/contact every time, you could just create them in the form itself:

    = semantic_form_for Message.new do |f|
    
    # ...
    
    = form_for Contact.new do |fc|
    

    This way you don’t have to keep an instance variable in your unrelated controllers around.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Form element: $Form=new Zend_Form; $Form->setAction($this->view->url(array('controller'=>'auth','action'=>'create'),null,true)) ->setMethod('post') ->setAttrib('id','auth-form') ->removeAttrib('enctype'); As can be
I have got a form which a user can use to create a new
I have a form that lets users create new records, In the field that
In Rails 3.0 I have the standard 'new' form that creates a new record,
I have a strange one. Create a new form. Then add the following function
I have a small form inside a table. POSTing that form creates a new
I have a button element that I've created like so: $submit = new Zend_Form_Element_Button('submit');
I have a namespaced controller for some admin functionality. My create form does not
I have a button that will create a new entry (row in a table)
In C#, how do i create a new webpage that I can either use

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.