Get updates

Forms

Scott Q&A: How to include a Rails text field without a variable?

The form helpers in Rails are great. But what do you do when you want to collect some data that’s not tied directly to a variable in your model?

Continue Reading…

Scott Q&A: How to Set a Form’s ID in Rails?

HTML is not hard. Anyone who can program, in any language, should be able to write HTML with little or no training. Yet there are reasons why the HTML helper functions in Rails can be handy. Chief among them is the easy and fairly clean way you can incorporate variables and other constructs; after all, the idea here is to have an app generate some of the code rather than having to write every piece by hand.

I was happily marching to the tune of form_tag() when I decided that I wanted a little JavaScript function to interact with the form’s contents. Great, except the HTML form code being generated by that helper function wasn’t coming with its own id attribute.

I could probably have the JavaScript function refer to this particular form by indexing an array, but then it could break if I ever changed the layout of the page to include another form. Hardly ideal.

Question: How does one tell Rails what the form’s id should be when creating the form with the helper function (or the Ajax form_remote_tag)?

Continue Reading…

3DM Design is where Scott Drake publishes thoughts on programming web applications in JavaScript and Ruby.