Rutul Dave

Joined

650 Experience
5 Lessons Completed
0 Questions Solved

Activity

I have used keyword arguments for some of my methods before, but haven't really thought about why not use it for all methods with arguments?

Seems like there is no good reason to have the caller ever know the correct ordering for the arguments.

If verbosity of the code is the only issue with keyword arguments, is there a good reason to not use keyword arguments for all your methods?

More on keyword arguments from Thoughtbot - https://robots.thoughtbot.com/ruby-2-keyword-arguments

Thanks. It will be useful to have a + Add link as well.

A solution that works, but feels/looks "hacky" is hiding the "add another" link and then trigger the click to that link when the enter key is pressed.

$("#nestedModelAttribute").keyup(function (e) {
if (e.keyCode == 13) {
$('.add-another').trigger("click");
}
});

I got cocoon working as well as I want.
Next though, I want to use the capabilities of cocoon and customize a bit.

For example, instead of having a 'Add another' link under the nested model, I want to to add the input field for the nested model when the user presses the enter key after adding a record for the nested model. So I want to trigger link_to_add_association when 'enter' key is pressed.

Any suggestions on how best to do that?

Thanks Chris. I tried out cocoon and it was a pretty straightforward to use. I guess I will go with the safe answer on this project :-).

I am not sure what the consensus is on the best approach to handling nested model forms is.
The solution in https://gorails.com/episodes/forum-nested-attributes-and-fields-for can work, but doesn't seem like it can scale.

Chris mentioned cocoon - https://github.com/nathanvda/cocoon

And in the comments, Daniel Kehoe seems to suggest using ActiveForm.

How do folks generally do nested forms?

Nice episode Chris. A small note that might help people new to adding initializers is that you need to restart your app after you add the omniauth initializer so that localhost:3000/auth/twitter works as expected. Might throw a few people off if they follow your steps along and forget to restart the app.

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.