Hi, I am playing with some of the scaffold generated code, and I have a DATETIME field in my database, which corresponds to the creation date. The scaffold generates: <% datetime_select ''user'',''creation_ts'' %> This works great when I use User.new(params[:user]) in the controller, but what I want to do is make the creation_ts an attr_protected in the model because people shouldn''t be able to change it by sending additional request parameters, except for an administrative user. Is there an easy rails way to convert the datetime_select struct ie. (creation_ts(1i),creation_ts(2i)) to a date/time object rather than manually constructing a Time parseable string using the many request parameters? -- Thanks, Curtis
Just don''t use User.new(params[:user]). Manually assign all the attributes. Alternatively, you could check the params hash to see if it has an attribute named creation_ts, and delete it before assigning the params to your user. Also, just remove the select from the scaffold form. Pat On 8/4/05, Curtis Spencer <thorin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I am playing with some of the scaffold generated code, and I have a > DATETIME field in my database, which corresponds to the creation date. > > The scaffold generates: <% datetime_select ''user'',''creation_ts'' %> > > This works great when I use User.new(params[:user]) in the controller, > but what I want to do is make the creation_ts an attr_protected in the > model because people shouldn''t be able to change it by sending > additional request parameters, except for an administrative user. > > Is there an easy rails way to convert the datetime_select struct ie. > (creation_ts(1i),creation_ts(2i)) to a date/time object rather than > manually constructing a Time parseable string using the many request > parameters? > > -- > Thanks, > Curtis > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Pat,> Just don''t use User.new(params[:user]). Manually assign all the attributes.I want to manually assign the date, and I want to use a datetime_select input field, mainly from an administrative end, such that the date could be changed using the webapp. I know I can do this manually, but I was wondering if there was a helper method to do the messy conversion of all of the sub components of the datetime_select into a Time object.> Alternatively, you could check the params hash to see if it has an > attribute named creation_ts, and delete it before assigning the params > to your user.Also, I think using the attr_protected/attr_accessible class methods in the model are the best way to lock down user settable parameters. -- Thanks, Curtis