Nested Form Rails UPDATING -


i hope good, need nested forms profile of user , respective car.

each user has 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 |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 fund ensure each time user posts car, can update profile. deputy nested form

 <%= simple_form_for(@auto) |f| %>    <%= f.error_notification %>     <%=f.fields_for @perfil |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 when want update not change user data if publish article. error in console is: unpermitted parameter: perfil

best regards friends.

you sending request auto controller, hence unpermitted parameter: perfil error , failure update.

you can add perfil controller:

has_many: :autos accept_nested_attributes_for: :autos 

then in view switch around this:

<%= simple_form_for(@perfil) |f| %>     <%= f.error_notification %>     <%= f.label :nombre %><br/>     <%= f.text_field :nombre %>     ...     <%=f.fields_for :auto |auto_builder|%>         <p>         <%= auto_builder.association :region %><br/>     ... 

see page more info: http://api.rubyonrails.org/classes/activerecord/nestedattributes/classmethods.html


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -