ruby - Does Rails have a way to convert checkboxes from "on" to true? -


when controller receives params of checked checkbox comes "on" if box checked. in case i'm trying store value boolean, typically want values checkboxes. question is, rails have way automatically convert "on" (or exists) true/false or need following?

value = params[my_checkbox] && params[my_checkbox] == "on" ? true : false 

you can use:

value = !params[:my_checkbox].nil? 

as checkbox not return value if not checked (implied forum)


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -