Forum: Ruby on Rails Newbie: I just want to exclude two attributes when I call update_attributes

Posted by Don Schenck (Guest)
on 2013-01-19 04:03
(Received via mailing list)
I have two virtual attributes in my model. Let's call them 
"hours_worked"
and "minutes_worked".

I use them to calculate "work_time", which is an integer I store -- it's
the total minutes worked (e.g. 3.5 hours is 210).

I want :hours_worked and :minutes_worked to NEVER appear in the 
database.

But when @foo.update_attributes(params[:foo]) is called, it bombs.

Any help would be appreciated. Thirty years software development 
experience
and I just can't seem to pick up Rails. ARGH!!!
Posted by Colin Law (Guest)
on 2013-01-19 10:19
(Received via mailing list)
On 18 January 2013 21:44, Don Schenck <don.schenck@gmail.com> wrote:
> I have two virtual attributes in my model. Let's call them "hours_worked"
> and "minutes_worked".
>
> I use them to calculate "work_time", which is an integer I store -- it's the
> total minutes worked (e.g. 3.5 hours is 210).
>
> I want :hours_worked and :minutes_worked to NEVER appear in the database.
>
> But when @foo.update_attributes(params[:foo]) is called, it bombs.

What do you mean it bombs?  Show us what is in params[:foo] and the
error you get.

Colin
Posted by Don Schenck (Guest)
on 2013-01-19 16:45
(Received via mailing list)
Colin --

I ended up using


.slice(:field1, :field2, :field4)


in my update. Works fine.

-- Don
Posted by Don Schenck (Guest)
on 2013-01-20 19:38
(Received via mailing list)
And in the Create method as well.

This FEELS wrong, but it works.
Posted by Dheeraj Kumar (Guest)
on 2013-01-20 19:52
(Received via mailing list)
You still haven't shown us what's in params[:foo] and the exact error 
you get.

--
Dheeraj Kumar
Posted by Jim ruther Nill (jimboker)
on 2013-01-21 01:17
(Received via mailing list)
On Mon, Jan 21, 2013 at 2:50 AM, Dheeraj Kumar 
<a.dheeraj.kumar@gmail.com>wrote:

>
> This FEELS wrong, but it works.
>
> You may want to look at strong_parameters
https://github.com/rails/strong_parameters


>
> > I have two virtual attributes in my model. Let's call them
> > But when @foo.update_attributes(params[**:foo]) is called, it bombs.
> To unsubscribe from this group, send email to
> "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



--
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.