开发者

Replace the Boolean Characters from SQL as Text in Rails

I am having a data of boolean datatype values such as True/False in sql database column. I created an array of T/F using the find_by_sql (select) options. Now I need to print the array not as True/False. Instead of that I have to print "It Occurs", if data populated as Tru开发者_Go百科e. nothing should be printed if it is false. How I can prints the alternative values of column of sql without changing the table.

TRUE = "It Occurs" FALSE = ""

Advance Thanks Palani Kannan


You can do it in your select statement...

SELECT if(column=1,"It Occurs","") as display_text FROM somethings ...

Or if you need to do it after the fact, use #map on the array:

array_as_text = array.map{|x| x ? "It Occurs" : ""}

Either way you should end up with something like: ["It Occurs","","","It Occurs"]

If you want to provide more details to get a clearer answer, you should do so.


Its working with this script,

Table Model

def combined_value if col == true "Conditions" else "Conditions" end end

Table View <% @table.each do |table| %> <%= table.col%>

Thanks for giving ideas to everyone in this discussion

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜