GLosch / rails-cookbook

0 stars 0 forks source link

View can't save because model is undefined #5

Open GLosch opened 9 years ago

GLosch commented 9 years ago

I'm trying to hit the saveModel function here: https://github.com/GLosch/rails-cookbook/blob/master/app/assets/javascripts/backbone/views/RecipeView.js#L15

but this.model is undefined. When the recipeView is instantiated, it's getting a model passed to it here: https://github.com/GLosch/rails-cookbook/blob/master/app/assets/javascripts/backbone/views/FormView.js#L57

...but when the RecipeView.saveModel() function is hit, the view no longer has a model associated with it.

andrewfritz86 commented 9 years ago

OK. Is the latest code pushed?

andrewfritz86 commented 9 years ago

Also is there a dummy user login you have offhand?

GLosch commented 9 years ago

Yeah it's up to date, debugger statement included :-)

GLosch commented 9 years ago

passing in the el property when instantiating the recipeView allows the event handler to trigger the saveModel function. But now there's an error: Uncaught Error: A "url" property or function must be specified

GLosch commented 9 years ago

No route for /recipes. Checking my routes to see what's going on there

GLosch commented 9 years ago

progress! I added the user_id when the model is instantiated, so now it stores that in recipe_params on the backend.

Good news/bad news: it's saving the recipe to the dB! Bad news: it's saving every model on the page, not just the one that's clicked.