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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:36:49+00:00 2026-05-29T16:36:49+00:00

I have a problem with validations in rails 3. I have got a model

  • 0

I have a problem with validations in rails 3. I have got a model where i am simply trying to validate one of the field of the model form, that is that it should not be blank. But the problem is even though I have filled that text field still it shows the error. What could be the possible problems?
MODEL FILE:

class Page < ActiveRecord::Base

validates :title, :presence => true
end

_form.html.erb

<%= form_for(@page) do |f| %>
  <% if @page.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@page.errors.count, "error") %> prohibited this post from being saved:</h2>

      <ul>
      <% @page.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>
  <p>
    <%= f.label :title %><br />
    <%= f.text_field :title %>
  </p>
   <p>
    <%= f.label :body %><br />
    <%= f.text_area :body %>
  </p>
   <p>
    <%= f.label :author %><br />
    <%= f.text_field :author %>
  </p>
   <p>
    <%= f.label :email %><br />
    <%= f.text_field :email %>
  </p>
   <p>
    <%= f.label :reference %><br />
    <%= f.select(:reference,[['google',1],['yahoo',2],['MSN',3],['Ask',4]]) %>
  </p>
   <%= f.submit "Submit" %>
<% end %>

And here is my controller file:

class PagesController < ApplicationController

  def index
    @total = Page.count
    @pages = Page.find(:all)
  end

  def new
    @page = Page.new


  end

  def create
    @page = Page.new(params[:pages])
    if @page.save
        redirect_to pages_path, :notice => "The data has been saved!"
    else
        render "new"
    end
  end 

  def edit
    @page = Page.find(params[:id])

    if request.post?
      @page.title = params[:title]
      @page.author = params[:author]
      @page.email = params[:email]
      @page.body = params[:body]
      @page.reference = params[:reference]
      @page.save
      redirect_to :action => 'index'
    end
  end

  def destroy
    @page = Page.find(params[:id])
    @page.destroy
    redirect_to :action => 'index'
  end
end

My routes.rb is as follows:

Rorapp::Application.routes.draw do
  get "home/index"
  post "home/search"
  get "home/_help"
  get "home/create"
  get "pages/index"
  get "pages/new"
  post "pages/new"
  post "pages/edit"
  get "pages/edit"
resources :pages
  # The priority is based upon order of creation:
  # first created -> highest priority.

  # Sample of regular route:
  #   match 'products/:id' => 'catalog#view'
  # Keep in mind you can assign values other than :controller and :action

  # Sample of named route:
  #   match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
  # This route can be invoked with purchase_url(:id => product.id)

  # Sample resource route (maps HTTP verbs to controller actions automatically):
  #   resources :products

  # Sample resource route with options:
  #   resources :products do
  #     member do
  #       get 'short'
  #       post 'toggle'
  #     end
  #
  #     collection do
  #       get 'sold'
  #     end
  #   end

  # Sample resource route with sub-resources:
  #   resources :products do
  #     resources :comments, :sales
  #     resource :seller
  #   end

  # Sample resource route with more complex sub-resources
  #   resources :products do
  #     resources :comments
  #     resources :sales do
  #       get 'recent', :on => :collection
  #     end
  #   end

  # Sample resource route within a namespace:
  #   namespace :admin do
  #     # Directs /admin/products/* to Admin::ProductsController
  #     # (app/controllers/admin/products_controller.rb)
  #     resources :products
  #   end

  # You can have the root of your site routed with "root"
  # just remember to delete public/index.html.
   root :to => 'home#index'

  # See how all your routes lay out with "rake routes"

  # This is a legacy wild controller route that's not recommended for RESTful applications.
  # Note: This route will make all actions in every controller accessible via GET requests.
   match ':controller(/:action(/:id(.:format)))'
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-29T16:36:51+00:00Added an answer on May 29, 2026 at 4:36 pm

    The create method in your controller refers to param[:pages]. Should this be param[:page]?

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

Sidebar

Related Questions

I have a classic rails 3 form with a file field, everything works fine,
I have a problem with validation messages not showing after a redirect, even when
I have a strange problem with the validation I am writing on a form.
I have problem in some JavaScript that I am writing where the Switch statement
I have a simple user registration page in my rails app that has two
I am writing a wizard form in rails; e.g. multiple input pages for one
I'm learning Rails, and got into a little problem. I'm writing dead simple app
I have a form that contains the data to create a Product object. The
I have been really stuck on this problem. My validation for my model fails
I have a coming_soon_controller that displays a form for users to subscribe to an

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.