我想让这两个动作用一个javascript模板publication.js.erb响应,而不是为每个动作使用file.js.erb。
##AJAX CALLBACKS##
def publish
@myth = Myth.find(params[:id])
if @myth.update_attributes(:status=>2)
#change status to publish
@msg = "Your Myth has been Published"
@type = "alert-success"
else
@msg = "Your Myth has not been Published"
@type = "error-success"
end
respond_to do |format|
format.html { redirect_to root_path }
format.js
end
end
def unpublish
@myth = Myth.find(params[:id])
if @myth.update_attributes(:status=>0)
#change status to publish
@msg = "Your Myth has been Unpublished"
@type = "alert-success"
else
@msg = "Your Myth has not been Unpublished"
@type = "error-success"
end
respond_to do |format|
format.html { redirect_to root_path }
format.js
end
end