devise - What am I doing wrong? [Rails, belongs_to] -


stuck on nested forms..

order model:

class order < activerecord::base    belongs_to :user   accepts_nested_attributes_for :user  end 

user mode:

class user < activerecord::base    has_many :orders, dependent: :destroy   accepts_nested_attributes_for :orders    # include default devise modules. others available are:   # :confirmable, :lockable, :timeoutable , :omniauthable   devise :database_authenticatable, :registerable,          :recoverable, :rememberable, :trackable, :validatable  end 

form view:

=form_for @order |order|     =order.fields_for :user, @order.user |user|         .row             .col-md-3                 .form-group                     =user.label :first_name, "name"                     =user.text_field :first_name, :class => "form-control"             .col-md-3                 .form-group                     =user.label :last_name, "last name"                     =user.text_field :last_name, :class => "form-control"             .col-md-3                     =user.label :email, "email"                     =user.text_field :email, :class => "form-control"             .col-md-3                     =user.label :telephone, "phone"                     =user.text_field :telephone, :class => "form-control"          .row             .col-md-4.margin-top-15                 =order.submit 'send', :class => 'btn btn-success' 

orderscontroller:

class orderscontroller < applicationcontroller    def new     @order = order.new     if user_signed_in?        user = current_user     else        user = user.new     end   end    def create     @order = order.new order_attributes     @order.save   end    private      def order_attributes       params.require(:order).permit(:user_id, user_attributes: [:id, :user_id, :user, :first_name, :last_name, :email, :telephone, :password, :password_confirmation])     end  end 

so trying do:

user model has devise. want create order , assign user_id. on submit tells me "unpermitted parameter: user". order model creates column, nothing goes user model.

what doing wrong?

change:

params.require(:order).permit(:user_id, user_attributes: [:id,... 

to:

params.require(:order).permit(:user_id, user: [:id,... 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -