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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:55:26+00:00 2026-05-15T11:55:26+00:00

I am implementing a simple RoR webpage that collect emails from visitors and store

  • 0

I am implementing a simple RoR webpage that collect emails from visitors and store them as objects.

I’m using it as a mini-project to try RoR and BDD. I can think of 3 features for Cucumber:
1. User submits a valid email address
2. User submits an existing email address
3. User submits an invalid email

My question is, for scenarios 2 and 3, is it better to handle this via the controller? or as methods in a class? Perhaps something that throws errors if an instance is instantiated in sceanrio 2 or 3?

Implementation is below, love to hear some code reviews in addition to answers to questions above. Thanks!


MODEL:

class Contact < ActiveRecord::Base
    attr_accessor :email
end

VIEW:

<h1>Welcome To My Experiment</h1>
<p>Find me in app/views/welcome/index.html.erb</p>

<%= flash[:notice] %>

<% form_for @contact, :url => {:action => "index"} do |f| %>
<%= f.label :email %><br />
<%= f.text_field :email %>
<%= submit_tag 'Submit' %>
<% end %>

CONTROLLER:

class WelcomeController < ApplicationController
  def index
    @contact = Contact.new
    unless params[:contact].nil?
      @contact = Contact.create!(params[:contact])
      flash[:notice] = "Thank you for your interest, please check your mailbox for confirmation"
    end  
  end
end
  • 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-15T11:55:27+00:00Added an answer on May 15, 2026 at 11:55 am

    To perform the last two steps, I recommend you use rails validations. For example, try updating your model to look something like this:

    class Contact < ActiveRecord::Base
    
      attr_accessor :email
    
      validates_uniqueness_of :email
      validates_format_of :email, :with => /\A(\S+)@(\S+)\Z/i
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a simple private messenger using Django and am implementing message threading. Each
I'm implementing a service that has several different ways it can be accessed: Using
What's my best bet for implementing a simple chat client (2-person) in an ASP.NET
I am implementing a quite simple state-machine order processing application. It is a e-commerce
I am implementing a very simple file database. I have 2 basic operations: void
I am implementing a design that uses custom styled submit-buttons. They are quite simply
I'm making a very simple website with ROR. class Product < ActiveRecord::Base belongs_to :category
I have tried to find out the working solution for implementing simple events booking
I am implementing a simple directory listing script in PHP. I want to ensure
I am implementing a simple license-file system, and would like to know if there

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.