{"action":"created","issue":{"url":"https://api.github.com/repos/emilylordahl/wgiyp_app/issues/6","labels_url":"https://api.github.com/repos/emilylordahl/wgiyp_app/issues/6/labels{/name}","comments_url":"https://api.github.com/repos/emilylordahl/wgiyp_app/issues/6/comments","events_url":"https://api.github.com/repos/emilylordahl/wgiyp_app/issues/6/events","html_url":"https://github.com/emilylordahl/wgiyp_app/issues/6","id":75705035,"number":6,"title":"Making Rails and Backbone Friends","user":{"login":"emilylordahl","id":4001091,"avatar_url":"https://avatars.githubusercontent.com/u/4001091?v=3","gravatar_id":"","url":"https://api.github.com/users/emilylordahl","html_url":"https://github.com/emilylordahl","followers_url":"https://api.github.com/users/emilylordahl/followers","following_url":"https://api.github.com/users/emilylordahl/following{/other_user}","gists_url":"https://api.github.com/users/emilylordahl/gists{/gist_id}","starred_url":"https://api.github.com/users/emilylordahl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emilylordahl/subscriptions","organizations_url":"https://api.github.com/users/emilylordahl/orgs","repos_url":"https://api.github.com/users/emilylordahl/repos","events_url":"https://api.github.com/users/emilylordahl/events{/privacy}","received_events_url":"https://api.github.com/users/emilylordahl/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-05-12T19:05:13Z","updated_at":"2015-05-12T20:33:30Z","closed_at":null,"body":"## CONTEXT\r\n\r\n@harimohanraj89 @DrRobotmck @williamfshaw @bigtone1284\r\n\r\n##### WHAT USER STORY YOU ARE WORKING ON:\r\n\r\nI am working on the user story \"As a user, I want to save my search results to a profile so that I can  remember places that I've been to or want to visit.\"\r\n\r\nI am working on the `relationships` branch of my repo.\r\n\r\n##### WHAT YOU ARE TRYING TO DO:\r\n\r\nI am trying to get the rendered search to save to a user's profile when the save button is clicked.\r\n\r\n##### DETAILED DESCRIPTION OF THE BUG/ERROR:\r\n\r\nThe collection of search results is rendered with Backbone. I've set up tables with many to many relationships and can successfully create and remove relationships from the console, but I realized that is because I have a test market and business already in my database. That said, I'm not sure how to save a backbone model and then create the relationship on click with rails.\r\n\r\nMy controller is not very skinny, which is making me feel like I'm going about this the wrong way.\r\n\r\n```rb\r\nclass UsersController < ApplicationController\r\n\r\n\tdef index\r\n\t\trender json: User.all\r\n\tend\r\n\r\n\tdef show\r\n\t\t@user = User.find(params[:id])\r\n\r\n\t\trespond_to do |format|\r\n\t\t\tformat.html {}\r\n\t\t\tformat.json { render json: @user }\r\n\t\tend\r\n\tend\r\n\r\n\tdef new\r\n\t\t@user = User.new\r\n\tend\r\n\r\n\tdef create\r\n\t\t@user = User.new(user_params)\r\n\r\n\t\tif @user.save\r\n\t\t\trespond_to do |format|\r\n\t\t\t\tformat.html { redirect_to users_path }\r\n\t\t\t\tformat.json { render json: @user }\r\n\t\t\tend\r\n    else\r\n      respond_to do |format|\r\n        format.html { render :new }\r\n        format.json { render json: { error: 'New user not created', status: 400 } }\r\n      end\r\n    end\r\n  end\r\n\r\n\tdef edit\r\n\t\t@user = User.find(params[:id])\r\n\tend\r\n\r\n\tdef update\r\n\t\t@user = User.find(params[:id])\r\n\r\n\t\t@user.update(user_params)\r\n\r\n\t\trespond_to do |format|\r\n\t\t\tformat.html { redirect_to user_path(@user.id) }\r\n\t\t\tformat.json { render json: @user }\r\n\t\tend\r\n\tend\r\n\r\n\tdef destory\r\n\t\t@user = User.find(params[:id])\r\n\r\n\t\t@user.destroy\r\n\r\n\t\trespond_to do |format|\r\n\t\t\tformat.html { redirect_to new_user_path }\r\n\t\t\tformat.json { render json: @user }\r\n\t\tend\r\n\tend\r\n\r\n\t# def add_market\r\n\t# \tuser = User.find(params[:id])\r\n\t# end\r\n\r\n\t# def remove_market\r\n\t# \tuser = User.find(params[:id])\r\n\t# end\r\n\r\n\tdef add_business\r\n\t\tuser = User.find(params[:id])\r\n\t\tbusiness = Business.find(params[:id])\r\n\r\n\t\tuser.add_business(business)\r\n\r\n\t\trespond_to do |format|\r\n\t\t\tformat.html { redirect_to user_path(user) }\r\n\t\t\tformat.json { render json: @user }\r\n\t\tend\r\n\tend\r\n\r\n\tdef remove_business\r\n\t\tuser = User.find(params[:id])\r\n\t\tbusiness = Business.find(params[:id])\r\n\r\n\t\tuser.remove_business(business)\r\n\r\n\t\trespond_to do |format|\r\n\t\t\tformat.html { redirect_to user_path(user) }\r\n\t\t\tformat.json { render json: @user }\r\n\tend\r\n\r\n\tprivate\r\n\tdef user_params\r\n\t\tparams.require(:user).permit(:first_name,:last_name,:email,:password,:password_confirmation)\r\n\tend\r\n\r\nend\r\n```\r\n\r\n```js\r\nApp.Models.Business = Backbone.Model.extend({\r\n\turlRoot: '/users/:id/add_user'\r\n});\r\n```\r\n\r\n## WHAT I'VE TRIED\r\n\r\nI've been using Tunr's playlist as a guide for creating many to many relationships and can make this work in the console, but I'm not sure the best way to save a model to my DB and then add the relationship.  Can I do that by setting a URL in my model? That's what makes sense to me, but I'm not sure if I'm using the right route to achieve this. Or should I just be making an AJAX call?\r\n\r\nI've been reading some docs about trying to figure out how to save from backbone to rails and it seems that setting a URL in the model is the best way, but I am not sure what route that url should hit.\r\n\r\n## QUESTION\r\n\r\nIs there some sort of rails magic to save a backbone model? Now that I'm at this point where my collection has rendered, I'm not sure how to simultaneously save a model and create the relationship to the user.\r\n\r\n:heart:\r\nEmily"},"comment":{"url":"https://api.github.com/repos/emilylordahl/wgiyp_app/issues/comments/101411897","html_url":"https://github.com/emilylordahl/wgiyp_app/issues/6#issuecomment-101411897","issue_url":"https://api.github.com/repos/emilylordahl/wgiyp_app/issues/6","id":101411897,"user":{"login":"harimohanraj89","id":4241399,"avatar_url":"https://avatars.githubusercontent.com/u/4241399?v=3","gravatar_id":"","url":"https://api.github.com/users/harimohanraj89","html_url":"https://github.com/harimohanraj89","followers_url":"https://api.github.com/users/harimohanraj89/followers","following_url":"https://api.github.com/users/harimohanraj89/following{/other_user}","gists_url":"https://api.github.com/users/harimohanraj89/gists{/gist_id}","starred_url":"https://api.github.com/users/harimohanraj89/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harimohanraj89/subscriptions","organizations_url":"https://api.github.com/users/harimohanraj89/orgs","repos_url":"https://api.github.com/users/harimohanraj89/repos","events_url":"https://api.github.com/users/harimohanraj89/events{/privacy}","received_events_url":"https://api.github.com/users/harimohanraj89/received_events","type":"User","site_admin":false},"created_at":"2015-05-12T20:33:30Z","updated_at":"2015-05-12T20:33:30Z","body":"@emilylordahl What is the status of this issue?"}}