Francois, I know I sound like a broken record to all, but IMHO it is much easier to read and learn from code posted at gist.github.com or pastie.org.
I took the liberty of pasting for others more knowledgeable than me to review: http://gist.github.com/299429 http://pastie.org/816636 Thanks, Owen 2010/2/8 François Beausoleil <[email protected]> > Hi! > > I'm offering an import form for my users. The import model itself > isn't a real ActiveRecord model. How can I benefit from all of > DRYML's goodies, without using a hobo_model? > > Using a hobo controller, I have this error when rendering the new > form: > > HoboError in ImportsController#new > > No input tag for file:Object (this=nil) > RAILS_ROOT: /Users/francois/Projects/dons_amateurs > > Application Trace | Framework Trace | Full Trace > vendor/plugins/hobo/hobo/taglibs/rapid_forms.dryml:289:in `input' > /Users/francois/Projects/dons_amateurs/vendor/plugins/hobo/hobo/lib/ > hobo/dryml/template_environment.rb:328:in `_tag_context' > /Users/francois/Projects/dons_amateurs/vendor/plugins/hobo/hobo/lib/ > hobo/dryml/template_environment.rb:248:in `new_context' > /Users/francois/.rvm/gems/ruby-1.8.7-p248/gems/actionpack-2.3.5/lib/ > action_view/helpers/capture_helper.rb:129:in `with_output_buffer' > /Users/francois/Projects/dons_amateurs/vendor/plugins/hobo/hobo/lib/ > hobo/dryml/template_environment.rb:248:in `new_context' > /Users/francois/Projects/dons_amateurs/vendor/plugins/hobo/hobo/lib/ > hobo/dryml/template_environment.rb:328:in `_tag_context' > vendor/plugins/hobo/hobo/taglibs/rapid_forms.dryml:261:in `input' > vendor/plugins/hobo/hobo/taglibs/core.dryml:7:in `send' > vendor/plugins/hobo/hobo/taglibs/core.dryml:7:in `call_tag' > /Users/francois/Projects/dons_amateurs/vendor/plugins/hobo/hobo/lib/ > hobo/dryml/template_environment.rb:328:in `_tag_context' > /Users/francois/Projects/dons_amateurs/vendor/plugins/hobo/hobo/lib/ > hobo/dryml/template_environment.rb:248:in `new_context' > /Users/francois/.rvm/gems/ruby-1.8.7-p248/gems/actionpack-2.3.5/lib/ > action_view/helpers/capture_helper.rb:129:in `with_output_buffer' > /Users/francois/Projects/dons_amateurs/vendor/plugins/hobo/hobo/lib/ > hobo/dryml/template_environment.rb:248:in `new_context' > /Users/francois/Projects/dons_amateurs/vendor/plugins/hobo/hobo/lib/ > hobo/dryml/template_environment.rb:328:in `_tag_context' > vendor/plugins/hobo/hobo/taglibs/core.dryml:6:in `call_tag' > > I have mostly faked my way out of everything. Notice the model at the > bottom. But that error has me stumped... I'm probably returning a bad > value from some method. > > Thanks! > François > > class Import > attr_accessor :file, :dry_run > attr_reader :encoding, :imported > > def initialize(params={}) > @dry_run = true > params.each do |key, value| > send("#{key}=", value) > end > > # TODO: Allow user-specified encodings > @encoding = "windows-1252" > end > > def new_record? > true > end > > def dry_run=(value) > case value > when "1", 1, true > @dry_run = true > else > @dry_run = false > end > end > > def errors > @errors ||= ActiveRecord::Errors.new(self) > end > > def validate > errors.clear > errors.add_on_blank(:file) > return if @file.blank? > > errors.add(:file, "must be a ZIP file") unless > File.extname(@file.original_filename).downcase == ".zip" > errors.add(:file, "must not be empty") if > File.size(@file.path).zero? > return unless errors.empty? > > errors.add_to_base("dry-run specified: not importing") if @dry_run > > # more validations > end > > def valid? > validate > errors.empty? > end > > def save > return false unless valid? > # import > true > end > > # > # The next 3 methods are for ActiveRecord::Errors > # > > def self.human_name > self.name > end > > def self.human_attribute_name(attribute_name) > attribute_name.to_s.humanize > end > > def self.self_and_descendants_from_active_record > [self] > end > > # > # The following 20 or 30 methods are to support Hobo/ActiveRecord > # > > def self.has_lifecycle? > false > end > > def self.view_hints > class_name = "#{name}Hints" > class_name.safe_constantize or Object.class_eval("class > #{class_name} < Hobo::ViewHints; end; #{class_name}") > end > > Column = Struct.new(:name, :type, :default) > > def self.columns > [Column.new("id", :integer, nil), Column.new("file", :string, > nil), Column.new("dry_run", :boolean, true)] > end > > def self.content_columns > columns.select {|column| %w(file dry_run).include?(column.name)} > end > > def self.column_names > columns.map(&:name) > end > > def self.attr_protected(*args) > # ignored > end > > def self.column(name) > columns.detect {|column| column.name == name} > end > > def self.never_show?(*args) > false > end > > def self.creator_attribute > :creator_attribute > end > > def self.primary_content_attribute > :primary_content_attribute > end > > def self.attr_order > [:file, :dry_run] > end > > def self.reflections > Hash.new > end > > def self.name_attribute > :name_attribute > end > > def self.user_new(*args) > new(*args[1..-1]) > end > > def self.to_url_path > "#{name.underscore.pluralize}" > end > > def to_url_path > "#{self.class.to_url_path}/#{to_param}" unless new_record? > end > > def self.typed_id > HoboFields.to_name(self) || name.underscore.gsub("/", "__") > end > > def typed_id > "#{self.class.name.underscore}:#{self.id}" if id > end > > def creatable_by?(user) > true > end > > def editable_by?(user, field=nil) > true > end > end > > -- > You received this message because you are subscribed to the Google Groups > "Hobo Users" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<hobousers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/hobousers?hl=en. > > -- Thanks, Owen Owen Dall Barquin International 410-991-0811 -- You received this message because you are subscribed to the Google Groups "Hobo Users" 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/hobousers?hl=en.
