开发者

Rails, making certain multiparameter attributes optional?

Is there a method already part of Rails for making certain parameters option when part of a multiparameter attribute, for example say I'm prompting a user for their birthday, when saved the hash may look like this:

"birthday(2i)"=>"8",
"birthday(3i)"=>"17",
"birthday(1i)"=>"1980"}, ...

But the issue arises when say I want to allow the user to just provide their month and day, making the year optional, how would this work being a datetime o开发者_运维百科bject, I'm assuming you can't do this as a date object... but any ideas would be helpful.

Happy new year.


A date definitely needs a year.

If year is optional, I guess you even don't use it. Then you could simply set it by default so that you'll have nice dates objects with wrong years.

You could do it by adding the year in your params before passing them to the save methods. Or you can hide the year in your html and give it a value in your form (ugly way).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜