Sha256: 53ded138310201c266f82b7d9a4d6f26e28ca8563e72e6a08389dcde395c26ff
Contents?: true
Size: 1.51 KB
Versions: 26
Compression:
Stored size: 1.51 KB
Contents
<!-- Provides a button that will create a new resource. This is normally used with ajax attributes. ### Attributes All standard ajax attributes are supported, plus: - model: The class to instantiate, pass either the class name or the class object. If model is not supplied, the current context (aka this) must be a has-many association. - label: the button label. Rather than using this attribute, the best way to customize this label is to set the i18n key `<class_name>.actions.new` - fields: a hash containing fields and their values to set on the new object ### Example <create-button update="foo" label="New" fields="&{name: 'Hello'}"/> is equivalent to: <form with="&this.new" update="foo"> <field-list: replace> <hidden-field:name value="Hello"/> </field-list:> <submit: label="New"/> </form> --> <def tag="create-button" attrs="model, label, fields"><% fields ||= {} class_or_assoc = if model model.is_a?(String) ? model.constantize : model else this end new = class_or_assoc.new(fields) new.set_creator(current_user) label ||= ht("#{new.class.to_s.underscore}.actions.new", :default=>"New #{new.class.model_name.human}") %> <form with="&new" without-cancel param class="button_to" merge> <submit: label="&label"/> <field-list: replace> <% fields.each do |field, val| %> <hidden-field field="&field" value="&val"/> <% end %> </field-list:> </form> </def>
Version data entries
26 entries across 26 versions & 1 rubygems