I'm new with Rails and I'm creating a simple app.

I have these 3 files and would like to display an error message when
the form fails, saying the problem. Something like 'Title must be
filled.' .

I don't know how to do that.

Please help me.

Thank you very much,

Gabriel.

-------------------------------

# app\models\sfile.rb
class Sfile < ActiveRecord::Base
         validates_presence_of :title
end



# app\controllers\sfiles_controller.rb
class SfilesController < ApplicationController
         def index
                 @page_title = 'Free SWF Hosting'
                 @sfile = Sfile.new
         end

         def create
                 @sfile = Sfile.new(params[:sfile])
                 respond_to do |format|
                         if @sfile.save
                                 flash[:notice] = 'File was successfully 
created.'
                                 format.html { redirect_to(:action => 'index') }
                         else
                                 format.html { redirect_to(:action => 'index') }
                         end
                 end
         end
end



# app\views\sfiles\index.html.erb
<p>Upload your file:</p>

<% form_tag(:controller => "sfiles", :action => "create") do |f|%>

  <p>
    <%= label_tag :title, 'FIle Name: ' %><br />
    <%= text_field_tag :title %>
  </p>
  <p>
   <%= label_tag(:description, "File description (optional) :") %><br /
>
   <%= text_area_tag(:description, nil, :size => "44x6") %><br />
   <%= submit_tag("Update") %>
  </p>
<% end %>


-------------------------------

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to