I really don't know advice with validating user input. I'm begining with RoR. I read many pages about this issues, but I never get, what I want. Before RoR, I programmed in Java. My problem is: How I can do validate empty field and show error messages? Here are code fragments:
polls_controller.rb
class PollsController < ApplicationController
def create
@poll = Polls.new
@poll.question = params[:question]
@poll.author_ip = request.remote_ip
end
def show
end
def new
end
def edit
end
end
polls.rb
class Polls < ActiveRecord::Base
has_many :options
validates_presence_of :question, :message => 'Something is wrong...'
end
create.html.erb
<p>
<% form_tag polls_path do %>
<%= label_tag :question, "Enter your question:" %><br>
<%=text_field_tag :question, params[:question] %>
<%=submit_tag "Send" %>
<% end %>
</p>