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 7962651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:23:53+00:00 2026-06-04T05:23:53+00:00

That was probably a very badly worded question, but I’m curious how Rails knows

  • 0

That was probably a very badly worded question, but I’m curious how Rails knows to bring in the form data when you click edit. For example, if I scaffolded a model called Post, and typed in a title and content for that Post, later when I edit it, the form is automatically filled in.

I looked at the controller and the form partial, but it doesn’t seem like it contains anything to tell it to fill it up with the existing data.

The reason I am asking this is because I want to allow users to “import” other people’s posts into their form and edit it. How would I do this?

  • 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-04T05:23:55+00:00Added an answer on June 4, 2026 at 5:23 am

    To answer the first part of your question, start by looking at the link to edit your model – in the index view file (app/views/posts/index.html.erb) it will look like:

    <%= link_to 'Edit', edit_post_path(post) %>
    

    When you open the index page in your browser, this builds a link like:

    http://*servername*/post/*id*/edit
    

    The resource routing knows that this calls the edit action of the post_controller, and that the id value is in the URL.

    Now take a look at the edit action in your post_controller (app/controllers/posts_controller.rb) – it looks like:

    def edit
      @post = Post.find(params[:id])
    end
    

    all this does is use the id value that was passed through the URL to find the Post in the database with that id, and save it in the variable @post.
    If you look in the code of the edit view file (app/views/posts/edit.html.erb) it mostly just uses the form partial (/app/views/posts/_form.html.erb) and that file contains the code for rendering the actual form you see in the browser.

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

    This line starts building the form using the @post variable that got set in the PostsController edit action. Inside the block for this code, you see things like –

    <div class="field">
      <%= f.label :title %>
      <%= f.text_field :title %>
    </div>
    

    This code builds a text field in the form tied to the :title property of @post – if a value exists in that property, the text_field method knows to populate the text field with that value.

    The second part (‘I want to allow users to “import” other people’s posts into their form and edit it’) is a lot more open-ended and depends more on what you actually want to do in your app – you could just allow all users to see all other users posts and edit them directly (kind of like a wiki, but with destructive edits). Or you could make posts editable only by the user that created them, but viewable by others, and then you could create a controller action that allows a user to copy the contents of another user’s post into a new post owned by the current user. Or other things – it really just depends what you want.

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

Sidebar

Related Questions

I have a question that is probably very simple, but I cannot find an
I realize that this is probably a very basic question, but I have spent
My question is probably very simple but it could also be the case that
I'm very new to JS, and understand that my script is probably terrible, but
XML problem that's got me stumped, but is probably very simple... The XML is
Okay my question is probably very simple for some of you but I can
Hello I recently posted this question but very badly explained the problem, but i'll
I've got a problem that probably has a very easy solution, but I can't
I'm having a problem that's probably (hopefully) very easy to solve but I'm just
A newbie question and probably very bingable (had to use that word once :-)),

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.