0

I want to display various JS alerts all in a row. Below is an example of what I want:

def exec
  render :js => "alert('Exec function has started');" and return

  if was_executed_successful?
    render :js => "alert('Congratz! You're the champion');" and return
  else
    render :js => "alert('Loser!');" and return
  end
end

The problem of the code above is that it only displays the first alert.

What can I do to display all of them?

4

2 回答 2

0

一次只从一个控制器动作中渲染一个东西,所以你可以像这样修改你的代码:

def exec
 js = []
 js << "alert('Exec function has started')" 

 if was_executed_successful?
   js << "alert('Congratz! You're the champion')" 
 else
   js << "alert('Loser!')"
 end
 render :js => js * ";"
end
于 2013-07-24T20:25:26.610 回答
0

Rahul 是在正确的轨道上,但就像他说的,每个动作只有一个渲染,所以我认为它必须是

def exec
 js = "alert('Exec function has started');" 

 if was_executed_successful?
   js << "alert('Congratz! You're the champion')" 
 else
   js << "alert('Loser!')"
 end
 render :js => js
end

此外,这将一个接一个地显示两个警报;如果要显示 exec 函数的进度,则解决方案更复杂。

于 2013-07-24T20:28:13.450 回答