<%= pairs = if for_query_string query_params.to_a else hiddens = case fields when '*', nil this.class.column_names - ['type', 'created_at', 'updated_at'] else comma_split(fields) end pname = this.class.name.underscore hiddens.map do |field| val = this.send(field) ["#{pname}[#{field}]", val] unless val.nil? || field.to_sym.in?(this.class.attr_protected) || (this.new_record? && val == this.class.column(field).default) end.compact end pairs.map { |n, v| hidden_field_tag(n, v.to_s) if v && n.not_in?(skip) }.compact.join("\n") %> <%= ajax_attrs, html_attrs = attributes.partition_hash(Hobo::RapidHelper::AJAX_ATTRS) new_record = this.try.new_record? method = if method.nil? (action || web_method || new_record) ? "post" : "put" else method.downcase end html_attrs[:action] = action || begin target = if owner collection_name = this.class.reverse_reflection(owner).name this.send(owner).send(collection_name) else this end action = web_method || lifecycle object_url(target, action, :method => method) end if action.nil? && (html_attrs[:action].nil? || (lifecycle.nil? && new_record && !this.user_can_create?(current_user)) || (lifecycle.nil? && !new_record && !can_edit?)) Hobo::Dryml.last_if = false "" else if method == "put" # browsers don't support put -- use post and add the Rails _method hack http_method_hidden = hidden_field_tag("_method", "PUT") html_attrs[:method] = "post" else html_attrs[:method] = method end if update || !ajax_attrs.empty? # add an onsubmit to convert to an ajax form if `update` is given function = ajax_updater(:post_form, update, ajax_attrs) html_attrs[:onsubmit] = [html_attrs[:onsubmit], "#{function}; return false;"].compact.join("; ") end body, field_names = scope.new_scope :in_form => true do with_form_context { parameters.default } end hiddens = hidden_fields(:fields => hidden_fields, :skip => field_names) if new_record auth_token = if method.nil? || method == 'get' || request_forgery_protection_token.nil? '' else element(:input, {:type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token}, nil, true, true) end page_path = if request.post? || request.put? && params[:page_path] params[:page_path] else view_name.sub(Hobo::Dryml::EMPTY_PAGE, params[:action]) end page_path_hidden = hidden_field_tag("page_path", page_path) unless method == "get" hiddens_div = element(:div, {:class => "hidden-fields"}, [http_method_hidden, page_path_hidden, auth_token, hiddens].join) body = [hiddens_div, body].join if action.nil? # don't add automatic css classes if the action was specified if web_method add_classes!(html_attrs, "#{type_id}_#{web_method}_form") else add_classes!(html_attrs, "#{'new_' if new_record}#{type_id}") end end Hobo::Dryml.last_if = true element("form", html_attrs, body) end %> <%= if attributes[:type] element :input, attributes, nil, true, true elsif !(force || can_edit?) view else attrs = add_classes(attributes, type_id.dasherize, type_and_field.dasherize) attrs[:name] ||= param_name_for_this the_input = if (refl = this_field_reflection) if refl.macro == :belongs_to call_polymorphic_tag('input', attrs) or select_one(attrs) elsif refl.macro == :has_many if refl.options[:through] select_many(attrs) else raise NotImlementedError, "An input for has-many associations has not been implemented yet" end end else call_polymorphic_tag('input', attrs) or (call_polymorphic_tag('input', HoboFields.to_class(this_type::COLUMN_TYPE), attrs) if defined?(this_type::COLUMN_TYPE)) or raise HoboError, ("No input tag for #{this_field}:#{this_type} (this=#{this.inspect})") end if this_parent.errors[this_field] "#{the_input}" else the_input end end %> <%= text_area_tag(name, this, attributes) %> <%= check_box_tag(name, '1', this, attributes) + hidden_field_tag(name, '0') %> <%= password_field_tag(name, this, attributes) %> <% order = order.nil? ? [:year, :month, :day] : comma_split(order).*.to_sym -%> <%= select_date(this || Time.now, attributes.merge(:prefix => param_name_for_this, :order => order)) %> <% order = order.nil? ? [:year, :month, :day ] : comma_split(order).*.to_sym -%> <%= select_datetime(this || Time.now, attributes.merge(:prefix => param_name_for_this, :order => order)) %> <%= text_field_tag(name, this, attributes) %> <%= text_field_tag(name, this, attributes) %> <%= text_field_tag(name, this, attributes) %> <%= text_field_tag(name, this, attributes) %> <% labels ||= {} titleize = true if titleize.nil? options = this_type.values.map {|v| [labels.fetch(v.to_sym, titleize ? v.titleize : v), v] } %> <%= ajax_attributes, html_attributes = attributes.partition_hash(Hobo::RapidHelper::AJAX_ATTRS) url = object_url(this, method, :method => :post) add_classes!(html_attributes, "button remote-method-button #{method}-button") label ||= method.titleize if update || !ajax_attributes.empty? ajax_attributes[:message] ||= label func = ajax_updater(url, update, ajax_attributes) html_attributes.update(:onclick => "var e = this; " + func, :type =>'button', :value => label) element(:input, html_attributes, nil, true, true) else button_to(label, url, html_attributes) end %> <%= raise HoboError.new("no update specified") unless update ajax_attributes, html_attributes = attributes.partition_hash(Hobo::RapidHelper::AJAX_ATTRS) params = (params || {}).merge(this.class.name.underscore => fields) ajax_attributes.reverse_merge!(:message => label, :params => params, :method => :put) func = ajax_updater(object_url(this), update, ajax_attributes) html_attributes.reverse_merge!(:type =>'button', :onclick => func, :value => label) element :input, add_classes(html_attributes, "button update-button update-#{this.class.name.underscore}-button"), nil, true, true %> <%= in_place = false if in_place.nil? && this == @this && !request.xhr? url = object_url(this, :method => :delete, :subsite => subsite) if (Hobo::Dryml.last_if = url && can_delete?) attributes = attributes.merge(if image { :type => "image", :src => "#{base_url}/images/#{image}" } else { :type => "button" } end) label ||= "Remove" confirm = "Are you sure?" if confirm.nil? add_classes!(attributes, image ? "image-button" : "button", "delete-button delete-#{this.class.name.underscore.dasherize}-button") if url if in_place == false attributes[:confirm] = confirm if confirm attributes[:method] = :delete button_to(label, url, attributes) else fade = true if fade.nil? attributes[:value] = label attributes[:onclick] = "Hobo.removeButton(this, '#{url}', #{js_updates(update)}, {fade:#{fade}, confirm: #{confirm.inspect}})" element(:input, attributes, nil, true, true) end end else "" end %> <%= raise HoboError.new("no update specified") unless update fields ||= {} class_or_assoc = if model model.is_a?(String) ? model.constantize : model elsif Hobo.simple_has_many_association?(this) fields[this_field_reflection.primary_key_name] = this.proxy_owner.id this else raise HoboError.new("invalid context for ") end new = class_or_assoc.new(fields) new.set_creator(current_user) if can_create?(new) label ||= "New #{new.class.name.titleize}" ajax_attributes = { :message => message } class_name = new.class.name.underscore ajax_attributes[:params] = { class_name => fields } unless fields.empty? func = ajax_updater(object_url(new.class), update, ajax_attributes) element :input, add_classes(attributes.merge(:type =>'button', :onclick => func, :value => label), "button create-button create-#{class_name}-button"), nil, true, true end %> <% raise HoboError.new("Not allowed to edit") unless can_edit? blank_message ||= "(No #{this_type.name.to_s.titleize})" conditions = ActiveRecord::Associations::BelongsToAssociation.new(this_parent, this_field_reflection).conditions options ||= this_field_reflection.klass.all(:conditions => conditions).select {|x| can_view?(x)} #Todo: switch to autocompleter for id_name when too many records, and id_name supported select_options = options.map { |x| [ name(:with => x, :no_wrapper => true), x.id ] } select_options = select_options.sort if sort select_options.insert(0, [blank_message, ""]) if include_none || (this.nil? && include_none != false) attributes = add_classes(attributes, "input", "belongs_to", type_and_field) %>

To proceed please correct the following:

<% prompt ||= "Add a #{this_field.titleize.singularize}" options ||= this.member_class.all values = this %>
<% uri = "stay-here" if stay_here %> <% uri = session[:previous_uri] if go_back %>