README in josevalim-simple_form-0.2.0 vs README in josevalim-simple_form-0.2.1
- old
+ new
@@ -1,8 +1,8 @@
Simple Form
License: MIT
-Version: 0.1
+Version: 0.2.1
You can also read this README in pretty html at the GitHub project Wiki page:
http://wiki.github.com/josevalim/simple_form/
@@ -28,11 +28,12 @@
Then you start a script/console and type:
c = ContactForm.new(:name => 'José', :email => 'jose@email.com', :message => 'Cool!')
c.deliver
-Check your inbox and the e-mail will be there, with the sent fields.
+Check your inbox and the e-mail will be there, with the sent fields (assuming
+that you configured your smtp properly).
SimpleForm also support attachments, I18n, error messages like in ActiveRecord
(so it works with custom FormBuilders) and can also send the user request information
in the contact mail.
@@ -64,11 +65,11 @@
And in your controller:
@contact_form = ContactForm.new(params[:contact_form], request)
And the remote ip, user agent and session will be sent in the e-mail in a
-request information session. You can send to append any method that the
+request information session. You can give to append any method that the
request object responds to.
API Overview
------------
@@ -81,10 +82,13 @@
* :validate - When true, validates the attributes can't be blank.
When a regexp is given, check if the attribute matches is not blank and
then if it matches the regexp.
+ Whenever :validate is a symbol, the method given as symbol will be
+ called. You can then add validations as you do in ActiveRecord (errors.add).
+
* :attachment - When given, expects a file to be sent and attaches
it to the e-mail. Don't forget to set your form to multitype.
* :captcha - When true, validates the attributes must be blank.
This is a simple way to avoid spam and the input should be hidden with CSS.
@@ -93,10 +97,15 @@
class ContactForm < SimpleForm
attributes :name, :validate => true
attributes :email, :validate => /[^@]+@[^\.]+\.[\w\.\-]+/
attributes :message
+ attributes :screenshot, :attachment => true, :validate => :screenshot_required?
attributes :nickname, :captcha => true
+
+ def screenshot_required?
+ # ...
+ end
end
c = ContactForm.new(:nickname => 'not_blank', :email => 'your@email.com', :name => 'José')
c.valid? #=> true
c.spam? #=> true (raises an error in development, to remember you to hide it)