當MyController
foo
方法是通過Ajax調用,它可能會返回Javascript代碼是這樣的:Rails 3:如何從Controller發送Javascript代碼?
class MyController < ApplicationController
def foo
render :js => "alert('Hello');"
end
end
這有可能做類似返回時foo
時(不通過Ajax),通常被稱爲一個Javascript代碼的東西嗎?我會這樣做:
class Job < ApplicationController
def edit
if user_type == 'demo'
[Here I would like to display a Javascript alert saying that
the job cannot be edited in demo mode. How would you do this?]
else
@job = Job.find(params[:id])
end
end
end
JS的格式你要反對的Rails的非標準使用和HTTP – fl00r 2011-03-29 14:19:58