RailsCasts Pro episodes are now free!

Learn more or hide this

irit29's Profile

GitHub User: irit29

Comments by

Avatar

Sorry new to rails/ruby this is all that's needed...

ruby
@user = User.new(params[:user])
def create
if params["format"] == "json"
    @user.password = [params[:password]]
end
#etc..
Avatar

oops, wrong screen cast, I meant to put this in 3.1 Auth.

Avatar

This is what I cam up with for the time being...

ruby
def create
            t_params = params.dup

              if params["format"] == "json"
                    t_params.delete("action")
                t_params.delete("controller")
                t_params.delete("format")
                t_params.delete("user")

                @user = User.new(t_params)
              else
                @user = User.new(t_params[:user])
              end

            respond_to do |format|
                    if @user.save
                            format.html { redirect_to root_url, :notice => "Signed up!" }
                                format.json { render json: @user, status: :created, location: @user }
                    else
                            format.html { render action: "new" }
                            format.json { render json: @user.errors, status: :unprocessable_entity }
                    end
            end
        end
Avatar

This is what I cam up with for the time being...

ruby
def create
            t_params = params.dup

              if params["format"] == "json"
                    t_params.delete("action")
                t_params.delete("controller")
                t_params.delete("format")
                t_params.delete("user")

                @user = User.new(t_params)
              else
                @user = User.new(t_params[:user])
              end

            respond_to do |format|
                    if @user.save
                            format.html { redirect_to root_url, :notice => "Signed up!" }
                                format.json { render json: @user, status: :created, location: @user }
                    else
                            format.html { render action: "new" }
                            format.json { render json: @user.errors, status: :unprocessable_entity }
                    end
            end
        end
Avatar

Is it possible to do a post to create a new user via json?

I've added validates_presence_of :email, :on => :create

I'm trying.

POST /users.json HTTP/1.1
Content-Type: application/json

{
"email": "myuser@useremail.com",
"password": "1234",
"password_confirmation": "1234"
}

It picks up the email field but not the others. Is it even possible to do a post like this with the password_digest system?