Frage

I am trying to pass some values through a json api and I can not seem to get tags to be passed to the db:

Console Output:

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)

Current curl:

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"]}}'

The parameters in my controller:

 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

Any help is greatly appreciated.

War es hilfreich?

Lösung

Figured it out. Changed the tag list attribute to an array:

tag_list: []

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top