Hi guys,
I am newbie in Rails world and I am using the Agile Web Development with Rails book to learn Rails.
I am trying to create a simple example using validation, actually only one field on the User Interface and this field uses the validates_presence_of validation.
Although this is a simple example, it doesn't work for me. Below following the source code of the VIEW, CONTROLLER, MODEL.
View (index.html.erb) <h1>Products#index</h1> <%= error_messages_for :product %> <% form_for :product,:url => {:action => :create} do |form| %> Name: <%= form.text_field :name, :size => 30 %><br /> <%= submit_tag %> <% end %>
Controller (products_controller.rb) class ProductsController < ApplicationController
def index end
def create @product = Products.new(params[:product]) end end
Model (products.rb) class Products < ActiveRecord::Base validates_presence_of :name, :message => "This is a required field" end