Forum: Ruby on Rails text_field_tag question

Be2b7277cff8516117cbd7a33df7b03a?d=identicon&s=25 Dave Castellano (dcastellano1)
on 2014-08-16 22:32
Hi,

I'm using a text_field_tag to provide a place for user input which does
not need a model or table associated with it.  It is used for jQuery to
compare a users input with another field value.
If I place the text_field_tag within the form_for code for the page,
upon data entry it looks for a route which I do not want or need and an
error is generated.

<%= text_field_tag "answer_input", nil, autofocus: true, placeholder:
'Enter answer here' %>

If I place it outside the form_for it works, but then I can't
position it on the page where I want it very easily.

I am a novice and am wondering if I am either using the wrong type of
input field or really do need to keep it outside the form_for and deal
with its page positioning thru CSS.

Here is additional info...
If I use:

form_for
...
<input type="text" size="25" id="answer_box" placeholder="Enter answer
here">
...

If I type anything into the text box and hit return, I get same error:
No route matches [POST] "/questions/answer"

Thanks,

Dave Castellano
Be2b7277cff8516117cbd7a33df7b03a?d=identicon&s=25 Dave Castellano (dcastellano1)
on 2014-08-17 23:49
Dave Castellano wrote in post #1155335:
> Hi,
>
> I'm using a text_field_tag to provide a place for user input which does
> not need a model or table associated with it.  It is used for jQuery to
> compare a users input with another field value.
> If I place the text_field_tag within the form_for code for the page,
> upon data entry it looks for a route which I do not want or need and an
> error is generated.
>
Sorry,  looks like this is not a Rails problem at all.  The form is
submitted when I press the enter key by default so I guess I have to
disable it in jQuery!

> Thanks,
>
> Dave Castellano
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.