私はrails 3.2とrablでAPIを開発しています。私は、関連ACTION.json.rablビューを持って、各アクションについてレール付きAPI 3.2とrabl
class AssetsController < ApplicationController
respond_to :json
# GET /assets.json
def index
@assets = Asset.all
end
# GET /assets/1.json
def show
@asset = Asset.find(params[:id])
end
# GET /assets/1/edit
def edit
@asset = Asset.find(params[:id])
end
# POST /assets.json
def create
@asset = Asset.new(params[:asset])
@asset.save
end
end
:
は、基本的に私は、モデル「資産」、非常に簡単な関連するコントローラを有します。
例えば、私のindex.json.rablがある:私は、以下のコマンドを発行すると
object @assets
attributes :kind, :description
、資産オブジェクトが作成されますが、NULL値とされています
curl -XPOST -d 'kind=house' 'http://localhost:3000/assets.json'
また、ありますPOST/assets.jsonと "create"関数の間のマッピングが指定されていますか?
あなたは 'リソースを行うときにマッピングがroutes.rbをで指定されている:あなたがMethodeのカール
更新:あなたがあなたの
create
Methodeの中であなたが望むだけkind
ないasset[kind]
のように引数を渡します:assets'。あなたのrablビューテンプレートを投稿できますか? –@ jack-chuありがとう、私は使用しているrablファイルの例で質問を更新しました。マッピングに関して、POST/assets.jsonを「new」という名前のメソッドにマップするにはどうすればよいですか? – Luc