动态错误消息使其成为条件

时间:2013-05-27 12:08:33

标签: ruby-on-rails ruby

我根据自己的要求玩了一些API。作为回应我得到一些动态错误消息。我想把错误信息放在if条件中,所以在条件中我可以根据我的要求编写一些代码。

这是错误消息。

“errormessage”=>“令牌webapi2-26631123a246241356880的登录会话已过期或无效。”

此webapi2-26631123a246241356880将动态生成..我喜欢if条件时出现此动态错误消息。

2 个答案:

答案 0 :(得分:0)

h = {"errormessage"=>"Login session for token webapi2-26631123a246241356880 is expired or invalid."}
h["errormessage"].include? "webapi2-" #=> true
if h["errormessage"].include? "webapi2-" 
  #your code here
end

答案 1 :(得分:0)

@webapi = Webapi.find(params[:token])
if coondition true
  #your logic here
 else
  flash[:alert] = "Login session for token " + @webapi.token + "is expired or invalid."
  render :template => 'path/to/template'
end