Ruby on Rails
Wednesday, September 10, 2014
Hi Vivek,
But now I end up with another error:-
On Thursday, September 11, 2014 12:10:26 AM UTC+8, Vivek Sampara wrote:
-- Ok, I've update my form to:-
<%= form_for :user, url: admin_user_path(@user), method: :patch do |f| %>
<div class="form-group"> <%= f.label :username %><br> <%= f.text_field :username, :class => "form-control" %> </div>
<%= f.fields_for :profile_attributes, @user.profile do |profile| %>
<div class="form-group"> <%= profile.label : full_name %><br> <%= profile.text_field :full_name, :class => "form-control" %> </div> <% end %>
<div class="form-group"> <%= f.submit "Save", :class => "btn btn-primary" %> </div>
<% end %>But now I end up with another error:-
development.log
Started PATCH "/master/users/7" for 127.0.0.1 at 2014-09-11 00:21:01 +0800Processing by Admin::UsersController#update as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"23oUfOBaYAmcrfhW3R11F1x53lJAT760Shv0HqkmEzw=", "user"=>{"username"=>"lisa", "profile_attributes"=>{"full_name"=>"Evalisa Andria"}, "commit"=>"Save", "id"=>"7"} [1m [36mUser Load (0.4ms) [0m [1mSELECT `users`.* FROM `users` WHERE `users`.`id` = 7 LIMIT 1 [0m [1m [35mUser Load (0.3ms) [0m SELECT `users`.* FROM `users` WHERE `users`.`id` = 6 ORDER BY `users`.`id` ASC LIMIT 1 [1m [36m (0.2ms) [0m [1mBEGIN [0m [1m [35mProfile Load (0.3ms) [0m SELECT `profiles`.* FROM `profiles` WHERE `profiles`.`user_id` = 7 LIMIT 1 [1m [36m (1.0ms) [0m [1mROLLBACK [0mCompleted 422 Unprocessable Entity in 78ms
ActiveRecord::RecordNotSaved (Failed to remove the existing associated profile. The record failed to save after its foreign key was set to nil.): app/controllers/admin/users_controller.rb:26:in `update'On Thursday, September 11, 2014 12:10:26 AM UTC+8, Vivek Sampara wrote:
Ahmad,the parameters you're sending from your form should be like this :{"utf8"=>"✓", "authenticity_token"=>"23oUfOBaYAmcrfhW3R11F1x53lJAT7 60Shv0HqkmEzw=", "user"=>{"username"=>"lisa", "profile_attributes"=>{"full_ Evalisa Andriaasdasda"}}, "commit"=>"Save", "id"=>"7"}name"=>" Update your form ( name attribute )On Wed, Sep 10, 2014 at 8:58 PM, Amirol Ahmad <9w2...@gmail.com> wrote:Hi guys,--Im having a problem with my rails apps where error "Unpermitted Parameters: profile" appearUsersControllerdef editif @userrenderelseredirect_to admin_users_path, notice: "User profile not found."endenddef update# Rails.logger.debug "===> (1)"if @user.update(user_params)redirect_to edit_admin_user_path, notice: "#{@user.profile.nama_penuh} account has been updated."elserender 'edit'endendprivatedef set_user@user = User.find(params[:id])enddef user_paramsparams.require(:user).permit(:id, :login, :email, profile_attributes: [:user_id, :full_name]) end
edit.html.erb<%= form_for :user, url: admin_user_path(@user), method: :patch do |f| %><div class="form-group"><%= f.label :username %><br><%= f.text_field :username, :class => "form-control" %></div><%= f.fields_for :profile, @user.profile do |profile| %><div class="form-group"><%= profile.label :full_name %><br><%= profile.text_field : full_name, :class => "form-control" %></div><% end %><div class="form-group"><%= f.submit "Save", :class => "btn btn-primary" %></div><% end %>User.rbclass User < ActiveRecord::Basehas_one :profileaccepts_nested_attributes_for :profile #, update_only: true, allow_destroy: truevalidates :username, :uniqueness => { :case_sensitive => false }end
Profile.rbclass Profile < ActiveRecord::Basebelongs_to :uservalidates_presence_of :user_idvalidates_presence_of :full_nameend
development.logStarted PATCH "/master/users/7" for 127.0.0.1 at 2014-09-10 23:18:26 +0800Parameters: {"utf8"=>"✓", "authenticity_token"=>"23oUfOBaYAmcrfhW3R11F1x53lJAT7 60Shv0HqkmEzw=", "user"=>{"username"=>"lisa", "profile"=>{"full_name"=>" Evalisa Andriaasdasda"}}, "commit"=>"Save", "id"=>"7"} [1m [35mUser Load (0.3ms) [0m SELECT `users`.* FROM `users` WHERE `users`.`id` = 7 LIMIT 1[1m [36mUser Load (0.3ms) [0m [1mSELECT `users`.* FROM `users` WHERE `users`.`id` = 6 ORDER BY `users`.`id` ASC LIMIT 1 [0mUnpermitted parameters: profile[1m [35m (0.2ms) [0m BEGIN[1m [36mUser Exists (0.4ms) [0m [1mSELECT 1 AS one FROM `users` WHERE (`users`.`username` = 'lisa' AND `users`.`id` != 7) LIMIT 1 [0m[1m [35m (0.2ms) [0m COMMIT[1m [36mProfile Load (0.4ms) [0m [1mSELECT `profiles`.* FROM `profiles` WHERE `profiles`.`user_id` = 7 LIMIT 1 [0m
I really dont know what is the mistake. Please help.
Thanks in advance!
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com .
To post to this group, send email to rubyonra...@googlegroups.com .
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ .041f0101-a81a-48a5-960d- 99f386923860%40googlegroups. com
For more options, visit https://groups.google.com/d/optout .
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/a6d8f7fc-9f36-41cc-82fd-88648853d13b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment