我试图用 j子把一个 text子点击,并提出一些问题。 我在此提出了这个问题,但我对所提供的答案持怀疑态度,因为答案似乎过于复杂(这可能是正确的,但我没有执行过。
Ruby on Railways jQuery button Pointpope text_field
Confirmation of doing it the way Christian mention in the other question or something simpler would be great, and sample code would be greatly appreciated. As mentioned in the other question I am very new to both ROR and jQuery.
更引人注意这个问题......
The button exits in both the new and edit.html.erb and is located in a form_for block next to a text_field (I have a separate button to submit the form). I want to be able to populate the field using the Ruby method SecureRandom.urlsafe_base64.
- Am I correct in using a button_tag?
- Where should the javascript file be located, I ve read a bit about this and some mention creating an edit.js.erb file and have the controller also respond to javascript. I am a bit unsure about this process however and as I need similar functionality in the new and edit pages, one global jQuery function would be better.
- If calling a method from the controller through jQuery is right way could someone please provide some sample code of how this is done as I had no luck when trying. If it is possible to call SecureRandom.urlsafe_base64 from a js.erb file and have the field update each time the button is clicked that would be ideal.
正如在另一个问题上看到的那样,我做的是一件事,但现在却步不前,而且变得非常绝望。
I would be grateful for any help and sample code.
亲爱!