Thanks for this screencast Ryan. This definitely enhances the functionality of episode #165. These casts on dealing with multiple edits, models, nested_attributes etc are extremely helpful for my self.newbie to wrap my head around these things.
I love how you make the techniques in each screencast seem so simple, as in, "Why didn't I think of that!".
I think it inspires new guys like myself to sit back and look for a simple solution instead of over thinking a problem, which I tend to do all the time.
More times than not the solution is simple; it just takes a better understanding of the wonder that is rails!
Thanks for your work Ryan. I greatly appreciate it.
That's a great episode. Thanks a lot Ryan. It's very useful and perfect to put on practice on every rails project or any project. I like Ruby more. Simple and elegant. Thanks again Ryan.
Love the screenscasts! Can I recommend you do one on an administrative tool like Typus (http://intraducibles.com/projects/typus) or something similar. I have used Typus for the first time recently and found it extremely helpful in getting up and running quickly. It does require some configuration of YAML files but you also have the ability to override pretty much everything.
I cannot understand why you wouldn't do a GET request instead. I mean, sure it will be a long query-string but that also means you could bookmark edit pages. If you keep track of certain products and update them daily that would be excellent.
Or is it really necessary with POST like you said?
"params" is a Hash (actually a subclass of Hash, HashWithIndifferentAccess), and its "keys" and "values" methods return arrays in no particular order. It's probably not a good idea to assume they'll pair up properly every time. Even if it works in practice, it probably exploits an undocumented fact about the Hash implementation.
Something like the following might be more bulletproof. It removes the assumptions but does basically the same thing:
I tried the following code, the flash gets displayed, but the 'Product.find' is still getting executed resulting in the error :
"Couldn't find Product without an ID"
begin
rescue params[:product_ids].empty?
logger.error("No products selected for 'Edit Selected'" )
flash[:notice] = "Nothing selected for 'Edit Selected' action"
A Question: How would you implement a "mass edit" facility?
What I mean to say is: say you had an attribute which you want to set to the same thing for ALL rows selected on the front form. How do you do this with a single control?
how can I use nested_attributes with this approch? e.g. http://stackoverflow.com/questions/2445097/accepts-nested-attributes-with-model-update-for-multiple-models
One problem I ran into (and I'm not sure if it's my fault, or Rails 3, or something else) is that none of this worked until I added a = to <% fields_for ...
Hopefully that helps others, but in any case, thanks for the great info!
Thanks Ryan, for such a great episode. But I have come with a question..?
I would like to have a default check_box button so that all the fields are selected and the ids, are sent through post request. could you guide through...
Hey Ryan, thx for this.
I have a problem though with Mongoid
A Person model and Custom Attributes model. Person embeds_many custom_attributes. Everytime the update_attributes(params[:person] creates a brand new set of attributes with a new idea instead of updating the existing ones.
Any idea why and how to fix this ?
Thx
Rest is all similar as in the example but it isn't working for me. I went through the log. It didn't get any values in contact_ids. Where am I doing wrong. Need help.
Hi Ryan, another great railscast from you, congrats!
I'm looking for something similar, but on this case you need to select what you want to edit and then do it one by one... How can I edit them directly on the first screen, without having to go to another screen?
I would filter all the fields, for example, fields that aren't approved yet (being "approved" a boolean), and when I get that list of unapproved items, I would have the chance to edit all them at once!
This is awesome, I'd like to se this combined with Formtastic, thanks for the awesome screencast!
+1 for combination with Formtastic.
i love formtastic. would be great if it is standard like ryans nifty generators.
Thanks for this screencast Ryan. This definitely enhances the functionality of episode #165. These casts on dealing with multiple edits, models, nested_attributes etc are extremely helpful for my self.newbie to wrap my head around these things.
Much appreciated,
Branden
This is xcellent screencast. Keep up the good work Ryan. I will be using this in my upcomgin RoR project.
Thanks for this screencast Ryan.
+1 for combination with Formtastic.
Thanks for your work!
I love how you make the techniques in each screencast seem so simple, as in, "Why didn't I think of that!".
I think it inspires new guys like myself to sit back and look for a simple solution instead of over thinking a problem, which I tend to do all the time.
More times than not the solution is simple; it just takes a better understanding of the wonder that is rails!
Thanks for your work Ryan. I greatly appreciate it.
great episode, as usual :)
+1 for combination with Formtastic.
That's a great episode. Thanks a lot Ryan. It's very useful and perfect to put on practice on every rails project or any project. I like Ruby more. Simple and elegant. Thanks again Ryan.
Very nice episode, thanks a lot!
You said the route would best be a GET and I agree; why not add :method => :get on the form to make it so?
Favorite episode to date! Thanks.
Ryan,
Love the screenscasts! Can I recommend you do one on an administrative tool like Typus (http://intraducibles.com/projects/typus) or something similar. I have used Typus for the first time recently and found it extremely helpful in getting up and running quickly. It does require some configuration of YAML files but you also have the ability to override pretty much everything.
Keep up the good work! Thanks.
Awesome as ever. Perhaps someone would be kind enough to document f.error_messages in the API docs?
I watched it yesterday and was thinking it's trival, useless and will never use it. Or not soon.
And now it looks like it's perfect solution for my today's problem at work. Man, how do you do it?
Thanks Ryan! At times I feel like we work together. ;)
I cannot understand why you wouldn't do a GET request instead. I mean, sure it will be a long query-string but that also means you could bookmark edit pages. If you keep track of certain products and update them daily that would be excellent.
Or is it really necessary with POST like you said?
One of my favorite episodes.
also +1 for formtastic
Would be interesting to combine webforms2 with this. Following example is screaming at this screencast :)
http://webforms2.googlecode.com/svn/trunk/testsuite/003.html
Hmm, this line in the controller feels a little risky:
Product.update(params[:products].keys, params[:products].values)
"params" is a Hash (actually a subclass of Hash, HashWithIndifferentAccess), and its "keys" and "values" methods return arrays in no particular order. It's probably not a good idea to assume they'll pair up properly every time. Even if it works in practice, it probably exploits an undocumented fact about the Hash implementation.
Something like the following might be more bulletproof. It removes the assumptions but does basically the same thing:
keys = params[:products].keys
values = keys.map {|k| params[:products][k]}
Aside from that, thanks for all the helpful 'casts.
very nice one, thanks!
+1 for combination with formtastic
+1 for usually using formtastic in railscasts ;-)
Ryan,
I haven't tried this yet, but is this the solution to completing the "survey series" (#196, #197) ?
Or do you have something else ?
If so, I'd love to see a final episode to complete the survey app, i.e. where a user can answer the questions on the survey.
Mike
Ryan,
If you click 'Edit Checked' without anything checked you get a walkback:
Couldn't find Product without an ID
How do you trap that error / post an error message?
Mike
Ryan,
I tried the following code, the flash gets displayed, but the 'Product.find' is still getting executed resulting in the error :
"Couldn't find Product without an ID"
begin
rescue params[:product_ids].empty?
logger.error("No products selected for 'Edit Selected'" )
flash[:notice] = "Nothing selected for 'Edit Selected' action"
redirect_to products_path
end
@products = Product.find(params[:product_ids])
Awesome! Very handy!
Ryan - Great Cast once again!
A Question: How would you implement a "mass edit" facility?
What I mean to say is: say you had an attribute which you want to set to the same thing for ALL rows selected on the front form. How do you do this with a single control?
Cheers
In reply to myself, I checked out Episode 165
Result!
Another question:
How do you implement a check box that checks all the check boxes (if you know what I mean!)?
Cheers
how can I use nested_attributes with this approch? e.g. http://stackoverflow.com/questions/2445097/accepts-nested-attributes-with-model-update-for-multiple-models
Has anyone successfully migrated this Episode (198 - Edit Multiple Individually)example to RAILS 3.01?
I've hit a problem that I'm having trouble resolving - which is basically that the fields_for block is not outputting anything to the _fields partial.
Here's some further details:
http://pastie.org/1304524
Thank you.
thx a lot for this.
How about an "edit multiple records in one form, without checkboxes"?!
Using your products example.
thx!
Hey Ryan,
Thanks for a great railscast!
One problem I ran into (and I'm not sure if it's my fault, or Rails 3, or something else) is that none of this worked until I added a = to <% fields_for ...
Hopefully that helps others, but in any case, thanks for the great info!
Agreed, thnx!!
Thanks Ryan, for such a great episode. But I have come with a question..?
I would like to have a default check_box button so that all the fields are selected and the ids, are sent through post request. could you guide through...
cheers
Looks great, will definitely try this trick
How can I show validation errors?
Hey Ryan, thx for this.
I have a problem though with Mongoid
A Person model and Custom Attributes model. Person embeds_many custom_attributes. Everytime the update_attributes(params[:person] creates a brand new set of attributes with a new idea instead of updating the existing ones.
Any idea why and how to fix this ?
Thx
I am trying to use this concept to delete multiple objects at a time. I added a button this way,
Rest is all similar as in the example but it isn't working for me. I went through the log. It didn't get any values in contact_ids. Where am I doing wrong. Need help.
Cool but doesn't work if you mix new and existing records.
Hi Ryan, another great railscast from you, congrats!
I'm looking for something similar, but on this case you need to select what you want to edit and then do it one by one... How can I edit them directly on the first screen, without having to go to another screen?
I would filter all the fields, for example, fields that aren't approved yet (being "approved" a boolean), and when I get that list of unapproved items, I would have the chance to edit all them at once!
Is this possible? Anyone has done this?