AJAX Flashcards

You may prefer our related Brainscape-certified 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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to update existing code with rails?

A

Click the button, and update js and inside js send rails argument

How well did you know this?
1
Not at all
2
3
4
5
Perfectly