There is no real rails way to do this, since it's a javascript problem.
At best you could "polish" that a bit by using link_to_function.
If you take the example from the second link, you'll need to use the
whole submitViaEnter(evt) function anyway.
Only for form building rails code can be used and then in the text_field
:onkeypress="return submitViaEnter(event)"
I'm not sure though, if that would work with a text area. (At least
you'll lose the multiline functionality)
i've searched for a way to submit a form with the
enter key, but haven't found the rails way to do it.
My experience has been that if you've got a form in the browser and you hit
the enter key it submits the thing whether that's what you intended or not.
I'm on Windows so that may play a role in it. Does your Rails app behave
differently?
for a text_field it does submit the form with the enter key.
maybe i should revisit using the text_field instead of text_area. my
problem with using the text_field was i wanted a multi-row box. so, i
styled it, setting the height and width. but then when entering text
the words never wrapped, instead a scroll bar appeared and the entered
text kept going on one line.
i couldn't get the observer to pick up key presses in the text area.
so, i put them on the document and it works. it's not optimal, but it
gets my use case solved. thanks, again.
i ended up using this with an AJAX form_remote_for. and there was an
issue. if the user tabbed to the submit button and then hit enter he
ended up with 2 new objects being created: one for hitting the button
and one for triggering the observer. i added an additional check to
ensure the event was started from within the text area:
event.originalTarget.tagName == 'TEXTAREA'.