AJAX Flashcards
1
Q
What are the key elements to implement AJAX logic in rails? ( 5 keys )
A
- Button ( For example show/update random number)
- HTML ( where this number will be shown)
- Route (with method type)
- Controller action ( Generates number )
- JS action inside controller ( which will update our html with our number)
2
Q
How to run alert() from the controller?
A
# view button_to 'Alert', action_path, remote: true
controller
def action_name
render js: ‘alert(2)’
end
3
Q
How to run alert() through js partial?
A
# view button_to 'Alert', action_path, remote: true
# controller def action_name render partial: 'partial_name' end
# _partial_name.js.erb alert()
4
Q
How to update existing code with rails?
A
Click the button, and update js and inside js send rails argument