lundi 7 septembre 2015

Update in action create

I have three models,auto, perfil, and user. Each user has their own profile. I need that when you publish a new Auto you can update your profile user if the data are different or change in time. But not as used to update the action in the action create. I use nested attributes.

 def create
         current_user.perfil||= current_user.build_perfil
         @perfil = current_user.perfil
         @perfil.update_attributes(auto_params)

         @auto = @current_user.autos.new(auto_params)
          respond_to do |format|
       if @auto.save 
        format.html { redirect_to @auto, notice: 'Auto was successfully created.' }
        format.json { render :show, status: :created, location: @auto }
       else
         format.html { render :new }
         format.json { render json: @auto.errors, status: :unprocessable_entity }
      end
     end

Aucun commentaire:

Enregistrer un commentaire