The form is coming from a javascript template....so it isn't strictly
the usual rails form:
<form>
<label for='title'>Title</label>
<input name='title' type='text' />
<label for='body'>Body</label>
<textarea name='body'><%= model.get('body') %></textarea>
<button><%= model.isNew() ? 'Create' : 'Save' %></button>
</form>
also everything worked fine for the activerecord version....the model
had some function:
def to_json(options = {})
super(options.merge(:only => [:id, :title, :created_at, :body]))
end
that does nothing with the dm version (that I can tell or register
atm)...and it is not just the form.
Console created documents aren't rendered in the collection with
another type of error:
WITHOUT dm-serializer:
-------------------------------------
Processing by DocumentsController#index as JSON
SQL (0.164ms) SELECT "id", "title", "body" FROM "documents" ORDER
BY "id"
Completed in 25ms
NoMethodError (undefined method `encode_json' for #<Document @id=1
@title="none" @body="asdfadfadsfasf">):
app/controllers/documents_controller.rb:6:in `block (2 levels) in
index'
app/controllers/documents_controller.rb:5:in `index'
WITH dm-serializer
---------------------------
Started GET "/documents" for 127.0.0.1 at 2011-05-02 12:46:26 -0400
Processing by DocumentsController#index as JSON
SQL (0.124ms) SELECT "id", "title", "body" FROM "documents" ORDER
BY "id"
Completed 200 OK in 5ms (Views: 4.2ms | Models: 0.124ms)
.....and nothing
There is something I need to be doing that I don't know I need to be
doing to get the json in tune with dm -- my thoughts right now. I'll
just reiterate that the only change I made was swapping out all the
activerecord related code for dm related code.
On May 2, 5:20 am, Piotr Solnica <[email protected]> wrote:
> Hi,
>
> You should put document's params under :document key so you pass
> params[:document] to #create method. What happens in your case is that
> you pass entire params hash to #create which also includes :action
> name (which is hidden in the logs, but it is there).
>
> Also if you're using #create! all hooks are bypassed which includes
> validations, you probably want to call #create instead.
>
> Hope this helps
>
> Cheers
>
> # solnic
>
> On May 1, 11:03 pm, none1 <[email protected]> wrote:
>
> > I'm working through a basic demo of a backbone.js (derived
> > fromhttp://www.jamesyu.org/2011/01/27/cloudedit-a-backbone-js-tutorial-by...).
> > All examples I've found work with Activerecord.
>
> > It is very basic, but doesn't work when I recreate it using DM. I'm
> > new to js, but from what I can see the js is working but I haven't set
> > DM and rails to talk properly with the json coming from the browser:
>
> > The controllers below:
>
> > class DocumentsController < ApplicationController
>
> > def create
> > 21--> document = Document.create! params
> > render :json => document
> > end
>
> > end
>
> > Submitting a post to create:
>
> > Processing by DocumentsController#create as JSON
> > Parameters: {"title"=>"asdfasdf", "body"=>"asdfadsfs"}
> > Completed in 1ms
>
> > ArgumentError (The attribute 'action' is not accessible in Document):
> > app/controllers/documents_controller.rb:21:in `create'
>
> > If I create objects through the console, they don't get rendered
> > either and there is js errors indicating not being able to read the
> > response correctly.
>
> > I've found next to nothing about backbone/dm and I'm new to js/json.
> > I'd like to be able to move what I'm doing into more of an ajax
> > context, and found backbone.js to be something I can understand. The
> > post doesn't give anything I'm accustomed to from a regular form (e.g.
> > params[:document], but I haven't toyed with the form template itself
> > yet hmmmm). Do I need to work with dm-serializer, there is something I
> > need to do to the model, etc.?
>
> > example application here:
>
> > https://[email protected]/blueblank/dmbackbone-example.git
>
> > Any input appreciated. I'd like to be able to work this out and have
> > others be able to reference.
--
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en.