Dear All
i am a beginner of ruby ob rails , now there is one problem i dont know
how to resolve it,there two tables ,

one is reservation,colums are:
id(int),mbr_id(int),,qty_reserved(decimal),valid_date(datetime)
the other is member,columns are:
id(int),email(char),encrypted_password
(char),points_accumulated(decimal),points_reserved(decimal)

member sign in to make a reservation with the points_accumulated he has,
then in the controller of reservations, i define a methos to create a
new reservation and save it to the database, everythins is ok, but how
can i update the member attributes points_accumulated and
points_reserved?

i uses current_user.update_attributes() unser the create action of
reservation,but it doesnt work, it is nil,
any one can help me?
thanks

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Javier Quarite at Jan 17, 2012 at 11:31 am

    On Mon, Jan 16, 2012 at 11:44 PM, Daisy Di wrote:

    Dear All
    i am a beginner of ruby ob rails , now there is one problem i dont know
    how to resolve it,there two tables ,

    one is reservation,colums are:
    id(int),mbr_id(int),,qty_reserved(decimal),valid_date(datetime)
    the other is member,columns are:
    id(int),email(char),encrypted_password
    (char),points_accumulated(decimal),points_reserved(decimal)

    member sign in to make a reservation with the points_accumulated he has,
    then in the controller of reservations, i define a methos to create a
    new reservation and save it to the database, everythins is ok, but how
    can i update the member attributes points_accumulated and
    points_reserved?

    i uses current_user.update_attributes() unser the create action of
    reservation,but it doesnt work, it is nil,
    any one can help me?
    thanks
    let's say you got this

    def create

    @current_user = CurrenUser.new(params[:id])
    @current_user. points_accumulated =
    @current_user.points_accumulated + 1
    @current_user.save

    end

    * That's a way and it maybe even shorter, but I dont know what are the
    rules you have

    Javier

    --
    You received this message because you are subscribed to the Google Groups "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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Tim Shaffer at Jan 17, 2012 at 1:36 pm
    Just a note that you should be careful using this method to increment a
    value. It can cause a race condition.

    A safer method is to use increment_counter since it updates the value
    directly in the database, not using the current attribute value on the
    instance

    CurrentUser.increment_counter(:points_accumulated, params[:id])

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/npSlYyFnUvsJ.
    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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Javier Quarite at Jan 17, 2012 at 2:00 pm

    On Tue, Jan 17, 2012 at 8:36 AM, Tim Shaffer wrote:

    Just a note that you should be careful using this method to increment a
    value. It can cause a race condition.

    A safer method is to use increment_counter since it updates the value
    directly in the database, not using the current attribute value on the
    instance

    CurrentUser.increment_counter(:points_accumulated, params[:id])

    There are better ways instead of mine I guess :)
    but I just wanted to show it because that may be the problem

    Javier

    --
    You received this message because you are subscribed to the Google Groups "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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJan 17, '12 at 4:44a
activeJan 17, '12 at 2:00p
posts4
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2022 Grokbase