Is it possible to use ruby code in RJS files?
For example, the destroy.js.rjs
file
if @template == "viewer"
page["viewing_registry_#{@viewer_registry.id}"].replace_html :partial => "shared/request_viewer_link"
else
page["viewer_#{@viewer.id}"].visual_effect :DropOut, :duration => 2.0
flash.discard
end
This is the RJS file called from a destroy action that has a
def destroy
@viewer = Viewer.find(params[:id])
@viewer_registry = Registry.find(@viewer.registry_id)
@viewer.destroy
flash[:notice] = "Viewer deleted"
@template = params[:template]
params[:template] = nil
respond_to do |format|
format.html { redirect_to registry_path(@viewer_registry) }
format.js
end
end
So from an AJAX call, the RJS file is used for the response, and it gives a different response based on which template is calling the destroy action.
At the moment, the AJAX call is made, the record is destroyed, and then nothing happens, regardless of which template was calling for the destroy action. So I'm wondering whether it is not working simply because I can't use ruby code in an RJS file. Any ideas? Or am I doing it wrong entirely?
Thanks!