我试图通过json api传递一些值,我似乎无法将标记传递给db:
控制台输出:
Started POST "/api/v1/miboxes/" for 127.0.0.1 at 2014-03-15 18:29:23 -0500
Processing by Api::V1::MiboxesController#create as JSON
Parameters: {"mibox"=>{"content"=>"search", "user_id"=>"19", "name"=>"tags nine", "location"=>"attic", "tag_list"=>["home", "house", "shed"]}}
User Exists (0.1ms) SELECT 1 AS one FROM "users" WHERE "users"."authentication_token" = 'tWJ3nqnNx6yxzC6pkWyo' LIMIT 1
(0.1ms) begin transaction
SQL (0.5ms) INSERT INTO "miboxes" ("content", "created_at", "location", "name", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?, ?) [["content", "search"], ["created_at", Sat, 15 Mar 2014 23:29:23 UTC +00:00], ["location", "attic"], ["name", "tags nine"], ["updated_at", Sat, 15 Mar 2014 23:29:23 UTC +00:00], ["user_id", 19]]
ActsAsTaggableOn::Tag Load (0.1ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = ? AND "taggings"."taggable_type" = ? AND (taggings.context = 'tags' AND taggings.tagger_id IS NULL) [["taggable_id", 181], ["taggable_type", "Mibox"]]
(2.4ms) commit transaction
Completed 201 Created in 82ms (Views: 2.3ms | ActiveRecord: 4.3ms)
当前卷曲:
curl -v -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Token token="tWJ3nqnNx6yxzC6pkWyo"' -X POST http://localhost:4000/api/v1/miboxes/ -d '{"mibox":{"content":"search","user_id":"19", "name":"tags nine","location":"attic", "tag_list":["home", "house", "shed"]}}'
我的控制器中的参数:
def mibox_params
#params.require(:mibox).permit!
params.require(:mibox).permit(:content, :location, :myboximages, :myboximages_cache, :remove_myboximages, :name, :user_id, tag_list: [:taggings])
end
非常感谢任何帮助。
答案 0 :(得分:0)
想出来。将标记列表属性更改为数组:
tag_list:[]