I Not sure if you saw or not, I have docs for how to cobble this together with 
existing pieces. 
https://github.com/schneems/wicked/wiki/Building-Partial-Objects-Step-by-Step


-- 
Richard Schneeman
http://schneems.com


On May 25, 2016 at 1:54:53 AM, thomas sevestre (t...@tcare.fr) wrote:

The context param is ok for some cases, ie for implementing a state machine 
like the business logic of an order.

But in my opinion the model should not change wether it is edited in a single 
form or in a wizard. You should not need to edit the model when you move an 
input field from a view to anther... This should be handled in the controller. 
With the proposed patch :

    def uptade
      ...
      my_object.assign_attributes(params)
      my_object.save(partial_validation: params.keys)
      ...
    end

Done !

Let me know if you are interested with a PR


Le mercredi 25 mai 2016 00:44:01 UTC+2, Andrew Kaspick a écrit :
You can use the context param or a "form object" if you only need to do partial 
validations.

On Tue, May 24, 2016 at 12:12 PM, thomas sevestre <t...@tcare.fr> wrote:
Hello,

I've been looking for a solution to perform partial validation of a model.
This is often an issue when you have multiple forms to fill a single model (ie 
with wicked wizard gem).
They are multiple complicated solutions on the web but it would be fairly easy 
to implement inside the validation framework.

I can provide a patch if interested.

This could be the API:

    my_object.save(partial_validation: array_of_attributes_to_validate)

The modified functions of active_record/validations (on branch 4.2)

    def valid?(context = nil, partial_validation = nil)
      context ||= (new_record? ? :create : :update)
      output = super(context)
      if partial_validation
        (errors.keys - partial_validation).each do |attr|
          errors.delete(attr)
        end
      end
      errors.empty? && output
    end

    def perform_validations(options={}) # :nodoc:
      options[:validate] == false || valid?(options[:context], 
options[:partial_validation].map(&:to_sym))
    end

Let me know if interested

Regards,
Thomas
--
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to