dimanche 30 août 2015

Nested Form Rails UPDATING

I hope they are good, need to do nested forms with the profile of a user and their respective car.

each user has their own profile:

 class PerfilController < ApplicationController
      before_filter :authenticate_user!

   def index
   end

   def show
     @usuario = current_user
     @usuario.perfil ||= Perfil.new
     @perfil = @usuario.perfil
   end

  def update
     @usuario = current_user
     @perfil = @usuario.perfil
     respond_to do |format|
          if @usuario.perfil.update_attributes(perfil_params)
              format.html {redirect_to @usuario, notice: "Datos Actualizados" }
         else
              format.html {render action: "show"}
         end
      end
   end

   private
    def perfil_params
       params.require(:perfil).permit(:nombre, :apellido, :rut)

 end
 end

I want the fund to ensure that each time a user posts a car, you can update your profile. Deputy nested form

 <%= simple_form_for(@auto) do |f| %>
   <%= f.error_notification %>

   <%=f.fields_for @perfil do |perfil_builder|%>
         <p>
         <%= perfil_builder.label :nombre %><br/>
         <%= perfil_builder.text_field :nombre %>
         <%= perfil_builder.label :apellido %><br/>
         <%= perfil_builder.text_field :apellido %>
         <%= perfil_builder.label :rut %><br/>
         <%= perfil_builder.text_field :rut %>
         </p>
     <%end%>

   <div class="form-inputs">
      <%= f.association :region %>
      <%= f.association :ciudad %>
      <%= f.association :marca %>
      <%= f.input :modelo %>
      <%= f.input :version %>
      <%= f.input :año %>
      <%= f.input :patente %>
      <%= f.association :tipo_transmision %>
      <%= f.association :combustible %>
      <%= f.association :tipo_vehiculo %>
      <%= f.association :carroceria %>
 </div>

   <div class="form-actions">
      <%= f.button :submit, :id => 'submit' %>
   </div>
 <% end %>

The problem is when you want to update does not change the user data but if you publish the article. the error in the console is: Unpermitted parameter: perfil

Best regards friends.

Aucun commentaire:

Enregistrer un commentaire