我的控制器中有以下代码
def create
@severity = Severity.new(params[:severity])
if @severity.save
flash[:notice] = "Successfully created severity"
render 'save'
end
end
我试图让方法呈现除create.js.erb之外的另一个视图文件,但是控制器总是呈现默认值而不是save.js.erb。
关于什么可能出错的任何想法?
答案 0 :(得分:2)
def create
@severity = Severity.new(params[:severity])
if @severity.save
flash[:notice] = "Successfully created severity"
respond_to do |format|
format.js { render :template => "/path/to/save" }
end
end
end
或
def create
@severity = Severity.new(params[:severity])
if @severity.save
flash[:notice] = "Successfully created severity"
respond_to do |format|
format.js { render :file => "/path/to/save.js.erb" }
end
end
end
试试这个
def create
@severity = Severity.new(params[:severity])
if @severity.save
flash[:notice] = "Successfully created severity"
end
render :file => "/path/to/save.js.erb"
end