Rails 3 Using RJS and having it work in Internet Explorer
I have a rails 3 app that has a fair amount of ajax functionality that is quite complex, it works fine and dandy in every browser but IE, and while I'm not positive why, I'm guessing it has something to do with HTML5. Here are parts of my app (edited for brevity)
in the view:
<li id="category_<%= category.id %>">
<%= link_to "#{category.title}", new_categorization_path(current_user.id, :category_id => category.id), :remote => true %>
</li>
In the controller:
class CategorizationsController < ApplicationController
def new
@category = Category.find(params[:category_id])
@categorization = Categorization.create(:user_id => current_user.id, :category_id => params[:category_id])
render :update do |page|
page.replace_html "category_#{para开发者_Python百科ms[:category_id]}", "#{link_to "#{@category.title}", categorization_path(current_user.id, :category_id => @category.id), :method => :delete, :remote => true, :style => "background-color:yellow;"}"
end
end
This code works perfect in all other browsers but IE (using IE8 currently, but I believe it is the same in all versions of IE). In IE it seems to partially work, when I click on it, the link gets a yellow background (as it should), but it doesn't seem to update the HTML at all, when I check the source it seems to have stayed the same, and when I click on the link again nothing happens. Additionally, if I check the DB it doesn't seem to have created a new categorization at all.
What am I missing here? Mime types? Should I put the code in a separate js.erb file?
Thanks!
yo've used double quotes "
twice. try this (use '
ustead "
)
def new
@category = Category.find(params[:category_id])
@categorization = Categorization.create(:user_id => current_user.id, :category_id => params[:category_id])
render :update do |page|
page.replace_html "category_#{params[:category_id]}", "#{link_to '#{@category.title}', categorization_path(current_user.id, :category_id => @category.id), :method => :delete, :remote => true, :style => "background-color:yellow;"}"
end
end
I ended up doing all my relevant AJAX in a seperate UJS JS file, that seems to have done it.
A la: new.js.erb
精彩评论