David Kahn
2010-Aug-16 17:23 UTC
Form validation and processing w/o model (no Db/ActiveRecord)
All - Trying not to fight rails on this, basically have a form and all the same as would be with an ActiveRecord model except that there is no table. I started out using this article: http://stackoverflow.com/questions/315850/rails-model-without-database ...which is kind of a hack by inheriting ActiveRecord in to non-AR model but am running into some problems and just have the feeling that I am fighting rails and going to spend more time on this than the benefit warrants. All am looking to do is receive and validate form input, and ideally have the luxuries like Class.new(params[:object]), Class.update_attributes(params[:object]), and for the form to do similar highlighting and error feedback messages as AR. I found this plug-in: active_form (http://github.com/nesquena/active_form). Wondering if anyone has used or has better ideas. David -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Fernando Perez
2010-Aug-16 17:27 UTC
Re: Form validation and processing w/o model (no Db/ActiveRecord)
Here is what I do: class Tableless < ActiveRecord::Base def self.columns @columns ||= []; end def self.column(name, sql_type = nil, default = nil, null = true) columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null) end end Class Contact < Tableless column :address, :string column :message, :text validates_presence_of :message, :address end It works perfectly in Rails 2.3.8, it might break in Rails 3 I haven''t tested yet. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
David Kahn
2010-Aug-16 17:34 UTC
Re: Re: Form validation and processing w/o model (no Db/ActiveRecord)
On Mon, Aug 16, 2010 at 1:27 PM, Fernando Perez <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote: Here is what I do: class Tableless < ActiveRecord::Base def self.columns @columns ||= []; end def self.column(name, sql_type = nil, default = nil, null = true) columns << ActiveRecord::> > ConnectionAdapters::Column.new(name.to_s, > default, sql_type.to_s, null) > end > end > > Class Contact < Tableless > column :address, :string > column :message, :text > > validates_presence_of :message, :address > end > > > It works perfectly in Rails 2.3.8, it might break in Rails 3 I haven''t > tested yet.Thanks Fernando. That is exactly what I was doing (but getting an error) but your telling me it works perfectly for you made me look further and I found an error in a field name that I was validating --- so now all works well. Good to have confirmation that this structure is being used successfully by others. David On Mon, Aug 16, 2010 at 1:27 PM, Fernando Perez <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> Here is what I do: > > class Tableless < ActiveRecord::Base > def self.columns > @columns ||= []; > end > > def self.column(name, sql_type = nil, default = nil, null = true) > columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, > default, sql_type.to_s, null) > end > end > > Class Contact < Tableless > column :address, :string > column :message, :text > > validates_presence_of :message, :address > end > > > It works perfectly in Rails 2.3.8, it might break in Rails 3 I haven''t > tested yet. > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.