Rails Query with embedded jQuery -
There are options to select a section based on the previous selections in my form once I select the section And show how many questions are there in the section.
I am trying to count questions but can not understand the syntax. Every time a section is selected I am trying to update a @ counting variable. Then to add a line, specify the table name in the hidden field in my table.
How do you query this? The $ ('# question_section')
is the wrong syntax.
$ ('# query_section'). Change (function () {{lt;% @ count = question where (section: $ ('# query_section')) Calculation% & gt; $ ('input [name =' question_count "] '). Val (& lt ;% @ Count% & gt;);});
More information needed I basically do not think of the code in your view that you will have to write any rail query inside your jacket. It has become very easy.
So far I have assumed that the user with your form Get options for section for questions You must follow the steps.
You will force the event to change on your selected httm input.
$ ("# questions_section") .On (function ( ) {Var value = $ (this) .value () // find section value / text}}
Now add an action on your controller where you will calculate the question with the question Therefore, you will need to do things for this. The Registrar has to work in the following ways:
resources: ask questions # I believe there is a question processing: counting, on: archive ending
Now it will give you a way The URL will now return to the javascript part again.
$ ("# questions_section") (Function () {var value = $ (this) .val () // get what section value / text $ .agex ({url: '/questions/count.js', // You can skip data here: {Section: value} Success: work (data) {$ ('input [name =' question_count "] '). Val (data)}})})
Are ready with Now lets go to the controller.
def number number_of_questions = question. Selection ("different (section)"). Where (section: params [: section]). Number render: js = & gt; Number_of_questions
end
Well, that's the step you can follow, the direct query in the view layer is not acceptable. Responsibility-focused design does not encourage it. I hope I can give some indication from my point of view.
Comments
Post a Comment