ruby - Give user points when he sign in Rails 4 -


in app if user1 likes picture user2 clicks on "get now" button,and points user1 goes user2.and user1 respectively gets redirected final picture. use in controller

  def downloadpage     activerecord::base.transaction       if current_user.points >= @picure.pointsneeded          current_user.points -= @picture.pointsneeded         @picture.user.points += @picture.pointsneeded         current_user.save         @picture.user.save         redirect_to @picture.boxlink       else         redirect_to :back, notice: "you don't have enough points"       end     end   end 

question: how give user 7000 points when sign website,for first time?

i tried put in application controller

before_filter :give_points_to_last_user    def give_points_to_last_user     @user = user.last     @user.points = 7000     @user.save   end 

and did work,but above system didn't work,how many time user hits "get picture button",the 7000 points remain same,they don't decrease expected,it stays 7000,whatever do.

my user controller right now

class userscontroller < applicationcontroller   def new   end    def create     @user = user.create(user_params)   end     def show     @user = user.find(params[:id])   end    def destroy     @user.destroy   end    private    # use strong_parameters attribute whitelisting   # sure update create() , update() controller methods.    def user_params     params.require(:user).permit(:avatar, :points)   end end 

in users controller -

def create   @user = user.create(user_params)   @user.update(points: 7000) end 

try above code.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -