mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #20493 from dansteele/patch-1
Removed AJAX example with poor convention adherence
This commit is contained in:
commit
7fe770cf4e
1 changed files with 0 additions and 24 deletions
|
@ -191,30 +191,6 @@ $(document).ready ->
|
|||
Obviously, you'll want to be a bit more sophisticated than that, but it's a
|
||||
start. You can see more about the events [in the jquery-ujs wiki](https://github.com/rails/jquery-ujs/wiki/ajax).
|
||||
|
||||
Another possibility is returning javascript directly from the server side on
|
||||
remote calls:
|
||||
|
||||
```ruby
|
||||
# articles_controller
|
||||
def create
|
||||
respond_to do |format|
|
||||
if @article.save
|
||||
format.html { ... }
|
||||
format.js do
|
||||
render js: <<-endjs
|
||||
alert('Article saved successfully!');
|
||||
window.location = '#{article_path(@article)}';
|
||||
endjs
|
||||
end
|
||||
else
|
||||
format.html { ... }
|
||||
format.js do
|
||||
render js: "alert('There are empty fields in the form!');"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
NOTE: If javascript is disabled in the user browser, `format.html { ... }`
|
||||
block should be executed as fallback.
|
||||
|
|
Loading…
Reference in a new issue