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
Post a Comment