Rendering a different Javascript file in respond_to

Hi everyone, I am stuck in an (apparently) simple problem.
In my event_controller I have the i_like_it action:

def i_like_it
@event = Event.find(params[:id])

... # logic

respond_to do |format|
  format.js
end

end

In my case “i_like_it” is called with :method => PUT (it is an Ajax
call, “i_like_it.js.erb” will be returned as a script and it wil be
executed on the browser.)

I would like render a Javascript file with a different name (not
i_like_it.js.erb) , but I haven’t found any option in the Rails API
docs.

respond_to do |format|
format.js { render ??? }
end

Rails can render vanilla JavaScript with :js option, but I don’t want
use Javascript in the controller.

Do you have any suggestion ?

Thank you,
Alessandro DS

Ale Ds wrote:

Hi everyone, I am stuck in an (apparently) simple problem.
In my event_controller I have the i_like_it action:

def i_like_it
@event = Event.find(params[:id])

... # logic

respond_to do |format|
  format.js
end

end

In my case “i_like_it” is called with :method => PUT (it is an Ajax
call, “i_like_it.js.erb” will be returned as a script and it wil be
executed on the browser.)

I would like render a Javascript file with a different name (not
i_like_it.js.erb) , but I haven’t found any option in the Rails API
docs.

respond_to do |format|
format.js { render ??? }
end

Here you go-

respond_to do |format|
format.js { render :action => ‘different_name.js.erb’}
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs