Create.js.erb, destroy.js.erb: how these files fit into a Rails application

I was unable to find documentation that describes how and how create.js.erbthey destroy.js.erbfit into a Rails 3 application.

What is the logic of these Javascript file types in applications> controllers? How and when are they available?

+3
source share
3 answers

File extensions are associated with Mime types. Check out my answer here . This was written for Rails 2.2.2, but the same logic is still preserved. Note that the syntax respond_tohas changed in Rails 3.
Also, these files are not in app/controllers, but inapp/views/<controller_name>/

+2

XMLHttpRequest, , javascript.

:

class MyController < ApplicationController

  respond_to :html, :js

  def show
    @my_model = MyModel.find(params[:id])

    respond_with @my_model
  end

end

show html html je js XMLHttpRequest.

+2

, ajax. , , varaialbes , .. create.html.erb. Ajax , rendereing create.js.erb.

, create.html.erb . create.js.erb javascript, .

:

$('#comments-box').html("<%= escape_javascript(index_comments(@commentable, @comments)) %>");
$('#comments-box-spinner').hide();
$('#flash').html("<%= escape_javascript(render(:partial => 'layouts/flash', :collection => flash)) %>");
+1

Source: https://habr.com/ru/post/1766134/


All Articles