user_controller.rb
def new
@
user = User.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @
user }
end
end
def create
#if request with JSON, which means multi-part will be used
logger.debug "create...."
logger.debug request.headers['Accept']
if(request.headers['Accept'] == "application/json")
data = ActiveSupport::JSON.decode(params[:user])
@
user = User.new(data)
else
@
user = User.new(params[:user])
end
respond_to do |format|
if @
user.save
format.html { redirect_to(users_url, :notice => "User #{@user.name} was successfully created.") }
#format.json { render json: @
user, status: :created, location: @
user }
#format.json { render :json => @
user.as_json(:only => [:name])}
#render :nothing => true
format.json {render json: @
user.as_json(:only => [:id, :hashed_password])}
else
format.html { render action: "new" }
format.json { render json: @
user.errors}# status: :unprocessable_entity }
end
end
end
--------------------------------------------------------------------------------------------------------
new.html.erb
<%= form_for(@user, :html => { :multipart => true }) do |f| %>
..................................................
<% end>
------------------------------------------------------------------------------
routes.rb
resources :users do
resources :trips do
resources :spots do
resources :photos
end
end
end