Closed TheCorp closed 9 years ago
When creating your post, Siteleaf will return additional information:
"values"=>[
{"value"=>"One", "slug"=>"one", "url"=>"/marketplace/tags/one"},
{"value"=>"Two", "slug"=>"two", "url"=>"/marketplace/tags/two"},
{"value"=>"Three", "slug"=>"three", "url"=>"/marketplace/tags/three"}
]
This information cannot be saved back as-is.
You'll want to do something like this instead:
post.taxonomy = [ {"key" => "Tags", "values" => ["One","Two","Three"]} ]
post.save
Also as a tip: If you only need to update one value (e.g. Title), you can do something like this to leave taxonomy and everything else unchanged:
post = Siteleaf::Post.new(id: 'abc123'), #where abc123 is existing post id
post.title = 'New Title'
post.save
Makes sense now!
Shouldn't the object be returned in a state that can be re-saved as is? Sorta breaks the whole Siteleaf site/page/post object concept in the gem.
Arguably yes, but that's how the V1 API works. You're also going to get better performance by only saving changes, so that's our recommendation. That said, we're working on a V2 behind the scenes which will improve many things including this. More to come!
:+1: Duly noted :)
For some reason when I apply a taxonomy I can't save a Post for a 2nd time. I am not sure if this is because of some specific issue using siteleaf-gem with Rails (4.1.9) and ActiveSupport but it seems very odd.
Here is an example using the taxonomy suggested in the main docs.
This outputs correctly and saves with no issues, it returns the new Post object with no errors. If I then try and just re-save the exact same siteleaf_post variable, I get the following:
Any ideas?