Git Product home page Git Product logo

dynamic_form's Introduction

DynamicForm

DynamicForm holds a few helpers method to help you deal with your Rails3 models, they are:

  • input(record, method, options = {})
  • form(record, options = {})
  • error_message_on(object, method, options={})
  • error_messages_for(record, options={})

It also adds f.error_messages and f.error_message_on to your form builders.

Read /lib/action_view/helpers/dynamic_form.rb for details of each method.


DynamicErrors

DynamicForm also includes DynamicErrors, which is a port of the custom-err-messages plugin, but built to work with Rails3. It gives you the option to not have your custom validation error message prefixed with the attribute name. Ordinarily, if you have, say:

validates_acceptance_of :accepted_terms, :message => 'Please accept the terms of service'

You'll get the following error message:

Accepted terms Please accept the terms of service

This plugin allows you to omit the attribute name for specific messages. All you have to do is begin the message with a '^' character. Example:

validates_acceptance_of :accepted_terms, :message => '^Please accept the terms of service'

Nigel Ramsay added the ability to specify a proc to generate the message.

validates_presence_of :assessment_answer_option_id, 
  :message => Proc.new { |aa| "#{aa.label} (#{aa.group_label}) is required" }

which gives an error message like: Rate (Accuracy) is required

Installation

DynamicForm can be installed as a gem in your Gemfile:

gem 'dynamic_form'

or as a plugin by running this command:

rails plugin install git://github.com/joelmoss/dynamic_form.git

Copyright (c) 2010 David Heinemeier Hansson, released under the MIT license

dynamic_form's People

Contributors

devdatta avatar imikay avatar jeremy avatar jgarber avatar joelmoss avatar josevalim avatar phiggins avatar ratnikov avatar sikachu avatar zr40 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dynamic_form's Issues

error_messages_for is escaping html

I'm using error_messages_for on my forms but it's escaping the html like so: http://cl.ly/DlDN

This is the code I'm using:

<%= error_messages_for(:form, :user, :message => "<strong>Opps, it doesn't look like you filled everything out properly.</strong><br>
            The fields marked in RED below must be filled out properly before you can continue.") %>

Anything I'm missing to get this to work properly? As you can see the input fields with the fieldWithErrors is also escaping html for some reason.

Thanks!

POROs and `@#<PORO>' is not allowed as an instance variable name

Not really an issue as I solved it, but something to note for other users of dynamic_form.

I was implementing dynamic_form with a Plain Old Ruby Object that includes ActiveModel::Validations, and was getting the error in the subject line when trying to use <%= f.error_messages %>.

I didn't find any other instances of this issue, but it can be solved by defining to_model in the PORO:

class Download
  include ActiveModel::Validations
  attr_accessor :name
  validates_presence_of :name

  def to_model
    self
  end
end

Thanks for the gem, works great.

Skip header, body etc

Hi,

Is there a way to simply skip activerecord.errors.template.header, activerecord.errors.template.header.body and display only error messages with f.error_messages ?

form helper does not work with Rails 3.0.7

I don't know at what point the form helper stopped working so I'm just going to say it doesn't work on 3.0.7 as that's the version I'm running on.

I have a nested model (although I tried this with a non-nested model and got the same problem) called Employer::Question. I created a haml form for the new view and called:

= form('question')

Reloading the page threw the error that Rails couldn't find the route :action => "employer/questions", :controller => "employer/questions".

I dug into the code some and it looks like the form method is expecting url_for to return the action name ("create" for example). But it's actually returning the path for the action ("employer/questions" in my case).

Changing the call to form_for to:

contents = form_tag(action, :method =>(options[:method] || 'post'), :enctype => options[:multipart] ? 'multipart/form-data': nil)

seems to fix the problem but all the tests break because the overridden url_for still returns the action. I don't know how to fix the tests so I haven't sent a pull request. I'm sorry for that.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.