how to apply validation if I using wicked gem - ruby-on-rails

I use wicked gem for devide page in multistep.
But there is one model.
How can i fire validation on this two different page
Is there any solution please help me...
There is two controller first is book_controller from that it enter in multistep controller from this controller it update book params.
and there is one model book_model form where i write validation
but in first page it fire all validation.
actually i want to fire few validation on first page and remaining validation in steps from

You can't do it on server side.
So, the solution do it on the client side.
http://jqueryvalidation.org/documentation/
http://railscasts.com/episodes/263-client-side-validations

Related

Ruby on rails form validation for user profiles advice needed

I have one model that holds validation rules for my edit_profiles page. On the edit profile page I'm using jquery accordion to split user edit_profile into different sections for users to edit information. Each section is a separate form.
e.g.
Basic info (form 1)
Personal Stats (form 2)
Favourite things (form 3)
About me (form 4)
My problem is successfully filling out information on one form and clicking update is unsuccessful because other validation rules that have been set are firing in because other forms are failing validation because they have not yet be filled in.
I've tried to use the validation_group gem but this seems to have no affect.
I'd like to know if there is an easy way to do this?
Can't I just bunch up validation rules for each form and put them in separate methods and only make them come into play when the update button from a matching form has been clicked?
So if the update button on form 1 is clicked the form_one_validations method would be fire for example and the unrelated validation methods won't.
I would really really appreciate an example of how to do this.
This is the action responsible for y edit_profile view:
def edit_profile
#profile = Profile.find_by_user_id(current_user.id)
end
It is based inside my profiles controller.
Kind regards
I ended up using :allow_blank
This way the fields don't have to be filled in but all other important validation rules are still enforced if they need to be.
I can propose you such approach: you can add additional fields to your model, something like "basic_info_completed" which will be set up once after user has filled all corresponding information. And make all necessary validations conditional and perform them only when such field is set to true. So before user fills all fields of profile section, they are all can be edited without validation, but after profile fields are completed, validation is turned on for that part of profile.

Rails 3: Show validation errors for simple_form with ajax

I am using rails3 with simple_form gem and :remote=>true (ajax).
How to I show validation error with :remote=>true?
Thanks
Use the javascript rails callbacks to do this.
See how do this here: http://www.simonecarletti.com/blog/2010/06/unobtrusive-javascript-in-rails-3/
My approach with this situation (validation errors on ajax submission) has been to pack up the errors off the form and handle them client side. I have been doing all my data using JSON so I send them back as a hash of input => long message. The input id allows me to easily turn on the form input "red" and the long message goes wherever you're putting the generalized messages...

Model validation being bypassed

I have a Comment model, in which I validate the presence of all fields. However, I used AJAX to submit and display a comment. Now, the validation is no more working and users can submit empty comments. How do I enforce validation?
If you want to use active record validation with AJAX, you need to implement it through rjs.
Have a look at these examples
http://railscasts.com/episodes/43-ajax-with-rjs
http://minimalbugs.com/questions/how-to-make-ajax-with-rjs
http://www.rubyinside.com/16-rjs-resources-and-tutorials-for-rails-programmers-5.html

Creating a specialised view filtering form in Rails

G'day guys, I have a current set of data, and I generate multiple analyses of this data (each analysis into its own active record item called a pricing_interval) using a helper function at the moment.
Currently to analyse the set of data, you need a start time(using datetime_select) an integer (using text_field) and a name (using text_field)
I would like on submission of the form to be redirected to the index page of my pricing_interval, as the values will be re-generated. Manually generating a range proves that my helper methods work.
How would I build a form that on submit would send parameters to a function in the form of (date,integer,name) so that it could immediately begin work whilst redirecting the user to server/pricing_intervals
Anything at all would help, I've spent hours over the past few days trying to get the rails form syntax working properly to no avail, a really straightforward guide to what I would implement to get this working would be amazingly appreciated.
I've looked through the form guides, as I'm not creating an object, but merely parsing params, there's got to be an easy way to do this, right?
You can use the rails form helper hidden_field_tag to put in whatever form fields you want. They are added to the params hash that your controller will see. You don't have to only send form fields that correspond to an ActiveRecord model.

Rails Form Validations for Multi-Model Forms

I am trying to build a Rails app with multiple models in a single form, and multiple forms on a single page. To make that work (according to my limited knowledge), I have to drop out of the scaffold code and the "form_for :model" helper and use "form_tag" instead. However when I do that, I lose the ability to automatically catch and report form validation errors in the view (with the error message in the flash[:error] and have the invalid fields highlighted.
If I have a controller method for a form that has to validate data from multiple models, how to I pass the validation errors back to the form? What do I have to do to get the invalid fields highlighted?
(For the longest time I didn't "get" Rails forms, because I thought they were useless Ruby wrappers for HTML code. Now that I am working in a non-Rails environment, I realize how much hard work they save because validation is tied to ActiveRecord validaions, and if a validation fails, the form can be reposted with the invalid fields hightlighted and a useful message in flash[:error]).
To add multiples models to a simple form, after rails 2.3 you just have to add accepts_nested_attributes_for in your model, the model that will be connected with your controllers and views, change the views to support information from another models (with field_for) and maybe build the reference objects in your controllers. Check these links:
http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes.
http://github.com/alloy/complex-form-examples

Resources