Another great railscast as usual. One thing that I'd like to know is if there's a way to make the checkboxes each have a different ID in the HTML code, and still have the form work?
I noticed in the example that every checkbox has the same ID, which is invalid, as ID's are meant to be unique within a XHTML document.
Thanks again Ryan for you great work.
@Leeky - It is actually the 'name' of the field that is referenced (and not the id) for submission. It is common practice (as many rails helpers do) to call the id and name the same. Im sure you can used the name as described in this screencast and use the dom_id plugin (http://topfunky.net/svn/plugins/dom_id/) to give your forms unique ids. This would be helpful for validation and for giving this task ajaxy goodness.
Great job Ryan. One thing your code snippet has "form_for" not "form_tag".
If we were to do this with multiple users, how can we first ensure that the task IDs belong to the current logged in user (in case someone edits the HTML and puts in a task ID that doesn't belong to them)?
@Rob
current_user.tasks.update_all(["completed_at=?", Time.now], :id => params[:task_ids])
end
Sorry two other things:
- submit_tag needs a closing %>
- it's ":collection" not ":collections"
:)
@JackVandaL, thanks, fixed. I gotta learn to copy and paste the code instead of retyping it. :/
Ryan,
Great episode. I have question concerning the controller. I see the pattern of always having a new -> create, edit -> update method.. But then I see some repeated code in the new and the create (like typically find the object by ID). Could use call the new method to do the setup of the default data and override them from the create method? Or is there a better way to refactor that?
This was great. Just wondering if there is a way to do this without using REST?
My app is not as clean as this one at this point and I am lost when it comes to getting the "collection" of data passed to the controller method.
I have a question. In this example the items disappear from the list when they are marked as complete.
What if you want to display the complete list all the time, but the check_box default value is based on the values from the tasks.
I am still a little bit confused on how I can give each of the checkboxes a unique id attribute. I'd like to create a label for each of my checkboxes which I am currently unable to do without unique ids.
Any help will be most appreciated.
@skoppy
If you are using fields_for in the way that Ryan is in his code, Rails should provide a unique id. If that's not working, you could always pass your own id as an HTML attribute:
f.check_box :property, :id => "some-unique-id"
Im trying to update Proyect-Users-role taking this approach. But i have an ActiveRecord::ReadOnlyRecord message. My assiciation table is projects_users and it has project_id, user_id, role_id as fields. How can this be done?
ryan, absolutely rate your casts. Best thing since cheese on toast.
Ive tried to create an ajax version of this using form_remote_tag but having problems (im fairly new at rails). Im wondering is implementing ajax functionality for this situation any more complicated than usual ajax stuff and hence why you didnt introduce it here?
Could you provide me any hints or warnings regarding this?
Hello Ryan, I have this solutin in an application, but since I updated to rails 2.3.3 the parameters are note passed as an array, but as a hash like this:
expected
"task_ids"=>["1","2","3","4"]
now I receive =>
"task_ids"=>[{"1"=>nil}, {"2"=>nil}, {"3"=>nil}, {"4"=>nil}]
do you know if it is an issue or the default new behavior should be as is....
thanks
Alexandre, I got this problem some year ago and fixed it somehow. Can u please provide us with your exact view-code and full params at submit...
I'm having the same issue as @Alexandre (Rails 2.3.3)
If we were to do this with multiple users, how can we first ensure that the task IDs belong to the current logged in user (in case someone edits the HTML and puts in a task ID that doesn't belong to them)?
we first ensure that the task IDs belong to the current logged in user (in case someone edits the HTML and puts in a task ID that doesn't belong to them)?
Hey Ryan, I know you did this tutorial a long time ago but I'm wondering what are the changes to do this with Rails 3.
(I hope you read this comment!)
Just to echo what others have said, after multiple searches across the web this solved my check_box problem in five minutes. Thanks so much!
his was great. Just wondering if there is a way to do this without using REST? If we were to do this with multiple users, how can we first ensure that the task IDs belong to the current logged in user
Thanks for sharing your article. I really enjoyed it. I put a link to my site to here so other people can read it. My readers have about the same interets
In this example the items disappear from the list when they are marked as complete.
Good post, I can’t say that I agree with everything that was said, but very good information overall:)






