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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:54:46+00:00 2026-05-22T22:54:46+00:00

Hey all,(im a beginner in rails) i’ve created a controller that look like that:

  • 0

Hey all,(im a beginner in rails)

i’ve created a controller that look like that:

class HomeController < ApplicationController

  def homepage
  end

  def showmsg
  @postword = params[:p]
  end

end

the showmsg view looks like that:

<%= @postword %>

and my homepage view looks like that:

  <%= form_tag( {:controller => 'home', :action => 'showmsg'}, :method => "post") do %>
  <%= text_field_tag(:p,@postword) %>
  <%= submit_tag("post") %>
  <% end %>

now i have a form that i can write something in it and it will show on the showmsg view.
i created a model with the param :posts with a :description “text” field too.
MY QUESTION is how do i implement the model in the code so any thing i write will be in a list with the things i wrote before, because now (obviously) anything if i write something its deleting the one i wrote before.

thank you all!

  • 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-22T22:54:47+00:00Added an answer on May 22, 2026 at 10:54 pm

    I would argue that you’re approach is not very rail’s like… so if you’re learning rails… you’re learning it wrong.

    Make a Model. Call it “Message”:

    rails generate model Message content:string
    

    remember to migrate (hopefully you have your databases setup properly):

    rake db:migrate
    

    Then in your controller, when you post, you can create message like this:

    def create #instead of showmsg... 'create' is the standard name for this
      Message.create(params[:message])
      @messages = Message.all
    end
    

    This will create the message in the database, and then it will get all the messages out of the database and put them into @messages.

    You need to edit your form so that it uses form_for. You need to pass it @message, which is an instance of Message.new that your first controller action created. You should call this new

    In your create.erb.html file, you show all the messages like this:

    <ul>
      <% @messages.each do |message| %>
        <li><%= message.content %></li>
      <% end %>
    </ul>
    

    I actually wouldn’t recommend showing all the messages in the create action – it should really happen in the index action and you should redirect… but we need to keep this simple. Just google this or watch some of Ryan’s screencasts and you’ll get it.

    And you’re done. This is the “Rails Way” to do things. It’s best to learn it the way they want you to learn it.

    I would also commend that you format your code properly by indenting, and start naming your methods to be real english. For example, showmsg is bad and show_message is a lot better.

    If all of this is totally confusing, then just create a new project, and then type:

    rails generate scaffold message content:string
    

    It will basically build the application you want and a lot more. You can just read the code and see how they did it.

    Hope it helps.

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

Sidebar

Related Questions

Hey all, have a slight problem here. In CakePHP I have a controller that
hey guys, beginner here. I have written a program that outputs files to .txt's
Hey all, simple question I'm sure, but I would like to have the body
Hey all, weird question. My company has an application from another company that records
Hey all, I am creating a login script that in one step, enters the
Hey all, I am setting up a PHP web app that will make use
Hey all i am trying to find some code that would allow me to
Hey all, I basically output content into a div like this using jquery: var
Hey all... I have a view controller (A) which on some action, alloc init's
Hey all, my Computational Science course this semester is entirely in Java. I was

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.