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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:42:37+00:00 2026-06-17T10:42:37+00:00

I have a simple static website written in rails 3. The site has one

  • 0

I have a simple static website written in rails 3.

The site has one controller called pages and each static page is served as view. Such as pages/home, pages/about, pages/prices, etc. This all works great.

I’ve now run into a problem where I need to add a simple contactus feature but I’m struggling to get my head round the model/controller/views for this.

I already have a pages controller with a contactus view, that view has details addresses etc. Now I somehow need to get a message model into the contactus view so I can populate the model attirbutes and send the email.

Can I / Should I just create a new message model from within the Pages Controller as in ,

  class PagesController < ApplicationController

  def contact

   def new
    @message  = Message.new
   end

   def create
     @message = Message.new(params[:message])
     if @message.valid?
      # TO DO send message here using OS mail program.

      redirect_to root_url, notice: "Message sent! Thank you for contacting us."
     else
       render "new"
     end  
    end
  end

  def about

  end

  def products

  end

  def portfolio

  end

  def services

  end

end

Or should I take out the contactus view from the pages controller and make new controller called messages ?

Thanks.

  • 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-17T10:42:38+00:00Added an answer on June 17, 2026 at 10:42 am

    I would have a separate controller called contact for example with new and create actions

    def new
    @message = Message.new
    end
    
    def create
    @message = Message.new(params[:message])
    if @message.valid?
      NotificationsMailer.new_message(@message).deliver
      redirect_to(root_path, :notice => "Message was successfully sent.")
    else
      flash.now.alert = "Please fill all fields."
      render :new
    end
    end 
    
    end
    

    Then a separate model to handle your messages

     class Message 
     include ActiveModel::Validations
     include ActiveModel::Conversion
     extend ActiveModel::Naming
    
     attr_accessor :name, :email, :subject, :body, :file
    
     validates :name, :email, :subject, :body, :presence => true
     validates :email, :format => { :with => %r{.+@.+\..+} }, :allow_blank => true
    
     end
    

    your attributes can be anything you like, obviously this is just an example of what you can do

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

Sidebar

Related Questions

I have made a simple web-page including a couple of static pages, a css
So I have a simple method called Invert : public static void Invert(this bool
I have a simple website(primarily static html/css) but for some reason some of the
I'm creating a fairly simple website. There are two static pages (Home and Portfolio)
I have a simple html/css-only static website on which I would like to add
I have a simple static website, based on HTML 5 boilerplate and the whole
I have a simple static website with a couple lines of text in it.
I have a simple website in django where the content is static. Where i
My heroku website's root page is essentially static, it has some ruby code in
I want to update/rewrite a small (10 page), simple website; 8 pages are entirely

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.