lib/dao/rails/lib/generators/dao/templates/conducer.rb in dao-4.2.1 vs lib/dao/rails/lib/generators/dao/templates/conducer.rb in dao-4.4.2

- old
+ new

@@ -1,64 +1,70 @@ +# -*- encoding : utf-8 -*- <% class_name = @conducer_name.camelize model_name = class_name.sub(/Conducer/, '') -%> + class <%= class_name %> < Dao::Conducer -## class_methods -# - class << <%= class_name %> - def all(params = {}) - records = <%= model_name %>.paginate(params) + def initialize(user, model, params = {}) + @user = user + @model = model - records.map! do |record| - new(record.attributes) - end - end + update_attributes( + :user => @user.attributes, + :model => @model.attributes, - def find(id) - raise NotImplementedError, <<-__ - this needs to return an instance based on the id - __ - end - end + :foo => 'bar' + ) -## instance_methods -# - def initialize - run_callbacks :initialize do + id!(@model.id) unless @model.new_record? + + mount(Dao::Upload, :logo, :placeholder => (@model.logo.try(:url) || 'http://placeholder.com/image.png')) + + case action + when 'new', 'create' + @attributes.email = @user.email + @model.field = @page.field + + update_attributes(params) + + when 'edit', 'update', 'show' + @attributes.email = @user.email + @model.field = @page.field + + update_attributes(params) end end + + validates_presence_of :something + def save - run_callbacks :save do - return(false) unless valid? + return(false) unless valid? - raise NotImplementedError, <<-__ - this needs to - - persist data to the db and get a new id - - set the id on the object : @attributes.set(:id => id) - - return true or false - __ + raise NotImplementedError, <<-__ + this needs to + - persist data to the db and get a new id + - set the id on the object : @attributes.set(:id => id) + - return true or false + __ - true - end + true end def destroy - run_callbacks :destroy do - id = self.id - if id + id = self.id + if id - raise NotImplementedError, <<-__ - this needs to - - un-persist data from the db - - set the id on the object to nil : @attributes.rm(:id) - - return this id of the destroyed object - __ + raise NotImplementedError, <<-__ + this needs to + - un-persist data from the db + - set the id on the object to nil : @attributes.rm(:id) + - return this id of the destroyed object + __ - end - id end + id end end