rails does not return data to filters.js.erb with ajax

1

This alert should not be executed after executing the filters method:

def filtros
    @apps= App.where(rol: params[:rol])
    .or(App.where(plataforma:params[:plataforma])
    .or(App.where(area: params[:area])))

    respond_to do |format|
        format.js{ render :json => @apps }
    end
end

Vista:

app/views/apps/filtros.js.erb
alert( "message" );
    
asked by Brayan Jimenez 29.03.2017 в 01:06
source

1 answer

0

It would be better if you give a brief description of what you want to do with that method since generally the render js is used to deliver partial by ajax.

Additionally you are not delivering the js file, as in the line:

format.js{ render :json => @apps }

What you are saying is that if you request that view in javascript format, do not return the view but the @apps variable in json format; to use @app in the script that you want to return, just call it in the view, it would look something like this:

Controller:

respond_to do |format|
  format.js {render layout: false}
end

View (the view file must end in .js.erb):

alert("<%[email protected]_json %>");
    
answered by 06.04.2017 в 16:27