我有一个update
操作,在成功更新后会执行edit
操作。
# PATCH/PUT /projects/1
# PATCH/PUT /projects/1.json
def update
respond_to do |format|
if @project.update(project_params)
format.html { render :edit, notice: 'Project was successfully updated.' }
else
format.html { render :edit }
end
end
end
在我看来,我想有条件地显示/隐藏一些页面元素,具体取决于@project.update
是否成功。
我考虑过的解决方案是将方法重写为:
# PATCH/PUT /projects/1
# PATCH/PUT /projects/1.json
def update
@was_successfully_updated = false # ADDED
respond_to do |format|
if @project.update(project_params)
@was_successfully_updated = true # ADDED
format.html { render :edit, notice: 'Project was successfully updated.' }
else
format.html { render :edit }
end
end
end
我觉得Rails可能有内置的东西来表明这一点。
有没有办法可以询问我的@project
实例以了解:
答案 0 :(得分:0)
<option value="drawCircle">Circle</option>
function draw() {
window[document.getElementById("mySelect").value]();
}
@model.new_record? # the opposite of `@model.persisted?`