{"action":"created","issue":{"url":"https://api.github.com/repos/ga-wdi-boston/full-stack-project/issues/415","repository_url":"https://api.github.com/repos/ga-wdi-boston/full-stack-project","labels_url":"https://api.github.com/repos/ga-wdi-boston/full-stack-project/issues/415/labels{/name}","comments_url":"https://api.github.com/repos/ga-wdi-boston/full-stack-project/issues/415/comments","events_url":"https://api.github.com/repos/ga-wdi-boston/full-stack-project/issues/415/events","html_url":"https://github.com/ga-wdi-boston/full-stack-project/issues/415","id":180697726,"number":415,"title":"Naming problem / incomplete model","user":{"login":"viohlet","id":17170398,"avatar_url":"https://avatars.githubusercontent.com/u/17170398?v=3","gravatar_id":"","url":"https://api.github.com/users/viohlet","html_url":"https://github.com/viohlet","followers_url":"https://api.github.com/users/viohlet/followers","following_url":"https://api.github.com/users/viohlet/following{/other_user}","gists_url":"https://api.github.com/users/viohlet/gists{/gist_id}","starred_url":"https://api.github.com/users/viohlet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/viohlet/subscriptions","organizations_url":"https://api.github.com/users/viohlet/orgs","repos_url":"https://api.github.com/users/viohlet/repos","events_url":"https://api.github.com/users/viohlet/events{/privacy}","received_events_url":"https://api.github.com/users/viohlet/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":15,"created_at":"2016-10-03T17:26:26Z","updated_at":"2016-10-04T15:41:07Z","closed_at":null,"body":"hi,\r\n\r\nI am having trouble calling call requests after adding authentication to the tokens in terminal. It is the naming (First I used user_stories, but my terminal -sometimes- changes it to UserStory like in my modal.\r\n\r\n**Error:**\r\n```\r\nStarted POST \"/user_stories\" for ::1 at 2016-10-03 13:20:36 -0400\r\nProcessing by UserStoriesController#create as */*\r\n  Parameters: {\"userstory\"=>{\"role\"=>\"visitor\", \"action\"=>\"play\", \"goal\"=>\"I do not want to register\"}}\r\n  User Load (0.2ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"token\" = $1 LIMIT 1  [[\"token\", \"2c0a8856b0e4f441d3eab8031539400b\"]]\r\nCompleted 500 Internal Server Error in 18ms (ActiveRecord: 1.5ms)\r\n\r\nNoMethodError (undefined method `userstories' for #<User:0x007fcf5d758d50>):\r\n  app/controllers/user_stories_controller.rb:21:in `create'\r\n\r\n\r\n  Rendered /usr/local/var/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (5.4ms)\r\n  Rendered /usr/local/var/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (2.1ms)\r\n  Rendered /usr/local/var/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.0ms)\r\n  Rendered /usr/local/var/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (46.8ms)\r\n```\r\n\r\n**user_stories.sh**\r\n```\r\n#create\r\ncurl --include --request POST http://localhost:3000/user_stories \\\r\n  --header \"Authorization: Token token=BAhJIiUyYzBhODg1NmIwZTRmNDQxZDNlYWI4MDMxNTM5NDAwYgY6BkVG--da28d67875224af25ced7d02223ee29267df53e5\" \\\r\n  --header \"Content-Type: application/json\" \\\r\n  --data '{\r\n    \"user_story\": {\r\n      \"role\": \"visitor\",\r\n      \"action\": \"play\",\r\n      \"goal\": \"I do not want to register\"\r\n    }\r\n  }'\r\n```\r\n\r\n**user_stories_controller.rb**\r\n```\r\nclass UserStoriesController < ProtectedController\r\n  before_action :set_user_story, only: [:show, :update, :destroy]\r\n```\r\n\r\n```\r\n  def create\r\n    @user_story = current_user.userstories.build(user_story_params)\r\n\r\n    if @user_story.save\r\n      render json: @user_story, status: :created, location: @user_story\r\n    else\r\n      render json: @user_story.errors, status: :unprocessable_entity\r\n    end\r\n  end\r\n```\r\n\r\n```\r\n  private\r\n\r\n  def set_user_story\r\n    @user_story = current_user.userstories.find(params[:id])\r\n  end\r\n\r\n  def user_story_params\r\n    params.require(:user_story).permit(:role, :string, :action, :goal, :project_id)\r\n  end\r\nend\r\n```\r\n\r\n**user_story.rb**\r\n```\r\nclass UserStory < ActiveRecord::Base\r\n  belongs_to :project\r\nend\r\n```\r\n\r\nMy projects' table curl requests work fine. And I make sure to change tokens every time I log in. Other naming I've tried to change in my user_stories_controller.rb include: userstories, userstory, userstorys, user_stories, UserStory..."},"comment":{"url":"https://api.github.com/repos/ga-wdi-boston/full-stack-project/issues/comments/251426505","html_url":"https://github.com/ga-wdi-boston/full-stack-project/issues/415#issuecomment-251426505","issue_url":"https://api.github.com/repos/ga-wdi-boston/full-stack-project/issues/415","id":251426505,"user":{"login":"viohlet","id":17170398,"avatar_url":"https://avatars.githubusercontent.com/u/17170398?v=3","gravatar_id":"","url":"https://api.github.com/users/viohlet","html_url":"https://github.com/viohlet","followers_url":"https://api.github.com/users/viohlet/followers","following_url":"https://api.github.com/users/viohlet/following{/other_user}","gists_url":"https://api.github.com/users/viohlet/gists{/gist_id}","starred_url":"https://api.github.com/users/viohlet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/viohlet/subscriptions","organizations_url":"https://api.github.com/users/viohlet/orgs","repos_url":"https://api.github.com/users/viohlet/repos","events_url":"https://api.github.com/users/viohlet/events{/privacy}","received_events_url":"https://api.github.com/users/viohlet/received_events","type":"User","site_admin":false},"created_at":"2016-10-04T15:41:07Z","updated_at":"2016-10-04T15:41:07Z","body":"Gracias @payne-chris-r for spotting the params user_story/userstory different! And thanks @jrhorn424 for walking through this issue with me one-on-one.\r\n\r\nSolution:\r\n```\r\n  def create\r\n    @user_story = UserStory.new(user_story_params)\r\n\r\n    if @user_story.save\r\n      render json: @user_story, status: :created, location: @user_story\r\n    else\r\n      render json: @user_story.errors, status: :unprocessable_entity\r\n    end\r\n  end\r\n```\r\n\r\nChange \r\n`@user_story = current_user.userstories.build(user_story_params)` for \r\n`@user_story = UserStory.new(user_story_params)`\r\n\r\nReasoning: \r\nMy user_story params do not recognize current_user. Also, the name of my modal is UserStory, and not userstories. Finally, I am not building a child out of a parent, but creating a child and then saving it on the next line `if @user_story.save` and so `new` is required and not `build`.\r\n\r\nLesson: Learn the meaning what I am coding, and templates are not my friend."}}
{"actor":{"display_login":"viohlet"}}