I need to pass two instance variables to a javascript file that is being used by an ajax request to update a user display. This is what I need to do:
respond_to do |format|
if @post.save
format.js { @post @user_vote } # <-- right here
else
format.html { redirect_to :back, :alert => 'There was an error in removing the vote' }
end
end
How is this done?
There is no need to pass the instance variables if you use js.erb files. You can directly put the rails tag and access those variables inside the js.erb file
Eg:
In your controller just put
and in js.erb file you can access the instance variable as