In my backoffice/users_controller.rb , I wrote a class to build the
permitted parameters

class Backoffice::UsersController < ApplicationController

     class UserParams
         def build params
             params.require(:user).permit(:email, :password,
:password_confirmation )
         end
       end

but using it in the create method,
   def create
     @user = User.new(UserParams.build(params))

  I get an error :
undefined method `build' for Backoffice::UsersController::UserParams:Class


  I guess I am wrong somewhere as the class is defined in the Backoffice
module... where I am wrong ?


thanks for help

--
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/d0de8d7d-b68e-4ba8-9976-302b10a09298%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Colin Law at Sep 17, 2013 at 5:32 pm

    On 17 September 2013 18:27, Erwin wrote:
    In my backoffice/users_controller.rb , I wrote a class to build the
    permitted parameters

    class Backoffice::UsersController < ApplicationController

    class UserParams
    def build params
    If you want a class method (rather than instance) this should be
    def self.build( params )
    params.require(:user).permit(:email, :password,
    :password_confirmation )
    end
    end

    but using it in the create method,
    def create
    @user = User.new(UserParams.build(params))

    I get an error :

    undefined method `build' for Backoffice::UsersController::UserParams:Class
    Because you have defined an instance method not a class method

    Colin

    --
    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/CAL%3D0gLuPhNwBZ04CFQdYvDjRxTrpJQJfrBwXnSzOECtPdQgoBA%40mail.gmail.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Erwin at Sep 18, 2013 at 5:59 am
    Thanks Colin... changed to :

       private

       def user_params
           params.require(:user).permit(:email, :password,
    :password_confirmation )
       end

    and cretae /update...
       def create
         @user = User.new(user_params)


    Le mardi 17 septembre 2013 19:31:43 UTC+2, Colin Law a écrit :
    On 17 September 2013 18:27, Erwin <yves_...@mac.com <javascript:>> wrote:
    In my backoffice/users_controller.rb , I wrote a class to build the
    permitted parameters

    class Backoffice::UsersController < ApplicationController

    class UserParams
    def build params
    If you want a class method (rather than instance) this should be
    def self.build( params )
    params.require(:user).permit(:email, :password,
    :password_confirmation )
    end
    end

    but using it in the create method,
    def create
    @user = User.new(UserParams.build(params))

    I get an error :

    undefined method `build' for
    Backoffice::UsersController::UserParams:Class

    Because you have defined an instance method not a class method

    Colin
    --
    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/d856d60b-61a3-4b84-b347-1f112be8c5db%40googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedSep 17, '13 at 5:27p
activeSep 18, '13 at 5:59a
posts3
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Erwin: 2 posts Colin Law: 1 post

People

Translate

site design / logo © 2021 Grokbase