mercredi 3 juin 2015

Rails-Grape Nested PUT routes for Ember

I create Grape-create action which work perfectly

desc "Create a project."
        params do
          group :project, type: Hash do
            requires :name, type: String, desc: "Name of project."
            requires :user_id, type: String, desc: "user id"
            requires :description, type: String, desc: "Description of project"
            requires :project_type_id, type: String, desc: "Type of project"
          end
        end
        post do
          Project.create!(
              name: params[:project][:name],
              user_id: params[:project][:user_id],
              description: params[:project][:description],
              project_type_id: params[:project][:project_type_id]
          )
        end

But, when I want to create a PUT action to edit some values, I have error from response in JSON: error: "project[id] is missing" My PUT code:

desc "Update a project."
        params do
          group :project, type: Hash do
            requires :id, type: String, desc: "project ID."
            requires :name, type: String, desc: "Name of project."
            requires :user_id, type: String, desc: "user id"
            requires :description, type: String, desc: "Description of project"
            requires :project_type_id, type: String, desc: "Type of project"
          end
        end
        put ':id' do
          Project.find(params[:project][:id]).update!(
              name: params[:project][:name],
              user_id: params[:project][:user_id],
              description: params[:project][:description],
              project_type_id: params[:project][:project_type_id]
          )
        end

What I do wrong with this?




Aucun commentaire:

Enregistrer un commentaire