Putting an edit form on an index page (as he does in the video) kind of makes Rails work like a javascript single page app. It seems to load and present the updates much faster, in addition to not having to redirect to a different page
Oh by the way, is it my imagination or is there absolutely no flashing when you click "discontinue checked" in solution 1? I always get flashing when I do this stuff - unless I am using ajax-y logic. Anyone?
I find the way validation errors are displayed in the third solution a bit odd. The validation error is always the same for each product, isn't it? Might as well display it only once then. Or am I missing something here?
Why did he make it a "collection type route" in the first rewrite of the edits (at 1:52 of the video)?
i.e. did he have to do it that way? What would be alternative ways to do it? why is this way better? Thanks if you can help.
Since he's editing multiple records, the operation is on the products collection, or at least a subset thereof.
It also means the url helper (discontinue_products_path) will have the plural form which seems appropriate. YMMV.
resources :products do
put :discontinue,:on => :collection
end
Agree or disagree.
Putting an edit form on an index page (as he does in the video) kind of makes Rails work like a javascript single page app. It seems to load and present the updates much faster, in addition to not having to redirect to a different page
Mike, see my question below...I am doing a similar thing and I definitely get a clear flash when the page is reloaded or re-rendered...
I suspect he's using Turbolinks which is explained in an earlier railscasts.
I highly recommend it as well. It is stupidly easy to implement and will be adopted in rails 4.0 if I recall correctly.
Just to clarify Turbolinks will be included by default in a new Gemfile generated with Rails 4 it is not built into the framework
Great episode, again :)
Oh by the way, is it my imagination or is there absolutely no flashing when you click "discontinue checked" in solution 1? I always get flashing when I do this stuff - unless I am using ajax-y logic. Anyone?
In Rails 4, this:
should be:
+1
This also works (IMO is preferred) in rails 3.2
I find the way validation errors are displayed in the third solution a bit odd. The validation error is always the same for each product, isn't it? Might as well display it only once then. Or am I missing something here?
Products could have validations like: price can't be lower than 2.99 if the category is "Games" - or something like that :)
I have a version of this that re-uses the form partial and avoids letting you edit fields that require unique values automatically:
https://github.com/spilth/rails-mass-update-test/blob/master/app/form_builders/mass_form_builder.rb
And
https://github.com/spilth/rails-mass-update-test/blob/master/app/views/books/mass_edit.html.erb
I have a feeling such operations should be refactored into a separate model (e.g. BulkProductsUpdater), this has several advantages:
I have the same scenarios with many to many categories. I have found difficulty with update method on product. Any ideas to help?
Is there any way to update attributes for miltiple objects with nested form?
I used this code in controller:
It is similar to example
But instead of updating the records, Ruby creates new ones and nullifies "work_id" in existing records.
What could cause this problem? Thank you!
First sign in through GitHub to post a comment.