{"action":"created","issue":{"url":"https://api.github.com/repos/ga-wdi-boston/full-stack-project/issues/611","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/611/labels{/name}","comments_url":"https://api.github.com/repos/ga-wdi-boston/full-stack-project/issues/611/comments","events_url":"https://api.github.com/repos/ga-wdi-boston/full-stack-project/issues/611/events","html_url":"https://github.com/ga-wdi-boston/full-stack-project/issues/611","id":208609953,"number":611,"title":"CREATE works in rails console but not in terminal","user":{"login":"doremaxime","id":24608045,"avatar_url":"https://avatars.githubusercontent.com/u/24608045?v=3","gravatar_id":"","url":"https://api.github.com/users/doremaxime","html_url":"https://github.com/doremaxime","followers_url":"https://api.github.com/users/doremaxime/followers","following_url":"https://api.github.com/users/doremaxime/following{/other_user}","gists_url":"https://api.github.com/users/doremaxime/gists{/gist_id}","starred_url":"https://api.github.com/users/doremaxime/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doremaxime/subscriptions","organizations_url":"https://api.github.com/users/doremaxime/orgs","repos_url":"https://api.github.com/users/doremaxime/repos","events_url":"https://api.github.com/users/doremaxime/events{/privacy}","received_events_url":"https://api.github.com/users/doremaxime/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2017-02-18T03:47:26Z","updated_at":"2017-02-18T04:18:33Z","closed_at":null,"body":"I am able to create an instance of the resource **climb** in the **bin/rails console** but when I try to do it with a terminal command I am getting an error and therefore not in the browser either.\r\nI expect my command to create a climb. \r\nI believe the solution may lie in the command, which I may be making a mistake in.\r\n\r\ncreate.sh:\r\n```\r\n#!/bin/bash\r\n\r\nAPI=\"${API_ORIGIN:-http://localhost:4741}\"\r\nURL_PATH=\"/climbs\"\r\ncurl \"${API}${URL_PATH}\" \\\r\n  --include \\\r\n  --request POST \\\r\n  --header \"Content-Type: application/json\" \\\r\n  --data '{\r\n    \"climb\": {\r\n      \"date\": \"'\"${DATE}\"'\",\r\n      \"grade\": \"'\"${GRADE}\"'\"\r\n      }\r\n    }' # \\\r\n  # --header \"Authorization: Token token=$TOKEN\"\r\n\r\necho\r\n```\r\n\r\ncontroller:\r\n```\r\n  # POST /climbs\r\n  def create\r\n    @climb = current_user.climbs.build(climb_params)\r\n\r\n    if @climb.save\r\n      render json: @climb, status: :created\r\n    else\r\n      render json: @climb.errors, status: :unprocessable_entity\r\n    end\r\n  end\r\n\r\n  def set_climb\r\n    @climb = current_user.climbs.find(params[:id])\r\n  end\r\n  private :set_climb\r\n\r\n  def climb_params\r\n    params.require(:climb).permit(:date, :grade, :id, :user_id)\r\n  end\r\n  private :climb_params\r\n```\r\n\r\nmodel:\r\n```\r\nclass Climb < ApplicationRecord\r\n  belongs_to :user\r\n\r\n  validates :date, presence: true\r\n  validates :grade, presence: true\r\nend\r\n```\r\n\r\ncommand I have tried (also restarted server):\r\n```\r\nDATE=\"1111-11-11\" GRADE=\"V1\" sh scripts/climbs/create.sh\r\nDATE=\"1111-11-11\" GRADE=\"V1\" USER_ID=\"1\" sh scripts/climbs/create.sh\r\nID=5 DATE=\"1111-11-11\" GRADE=\"V1\" USER_ID=\"1\" sh scripts/climbs/create.sh\r\nID=5 DATE=\"1111-11-11\" GRADE=\"V1\" USER_ID=1 sh scripts/climbs/create.sh\r\n```\r\n\r\nError message in terminal:\r\n```\r\nHTTP/1.1 500 Internal Server Error\r\nContent-Type: application/json; charset=utf-8\r\nX-Request-Id: 829201d6-905f-43fd-b0c2-aa5e7d7739a9\r\nX-Runtime: 0.246300\r\nVary: Origin\r\nContent-Length: 11481\r\n\r\n{\"status\":500,\"error\":\"Internal Server Error\",\"exception\":\"#\\u003cNoMethodError: undefined method `climbs' for nil:NilClass\\u003e\"\r\n```\r\nI did not paste the entire error message as it is quite long but can if it is actually needed.\r\n\r\nBecause the error message indicates that **undefined method climbs** I have tried setting the create in the controller to     **@climb = current_user.climbs.build(climb_params)** but then the error message is **undefined method climb**. This leads me to believe that the issue lies somewhere else...\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/ga-wdi-boston/full-stack-project/issues/comments/280820563","html_url":"https://github.com/ga-wdi-boston/full-stack-project/issues/611#issuecomment-280820563","issue_url":"https://api.github.com/repos/ga-wdi-boston/full-stack-project/issues/611","id":280820563,"user":{"login":"bernardlee","id":12991284,"avatar_url":"https://avatars.githubusercontent.com/u/12991284?v=3","gravatar_id":"","url":"https://api.github.com/users/bernardlee","html_url":"https://github.com/bernardlee","followers_url":"https://api.github.com/users/bernardlee/followers","following_url":"https://api.github.com/users/bernardlee/following{/other_user}","gists_url":"https://api.github.com/users/bernardlee/gists{/gist_id}","starred_url":"https://api.github.com/users/bernardlee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bernardlee/subscriptions","organizations_url":"https://api.github.com/users/bernardlee/orgs","repos_url":"https://api.github.com/users/bernardlee/repos","events_url":"https://api.github.com/users/bernardlee/events{/privacy}","received_events_url":"https://api.github.com/users/bernardlee/received_events","type":"User","site_admin":false},"created_at":"2017-02-18T04:18:33Z","updated_at":"2017-02-18T04:18:33Z","body":"Since you're going to let your users perform CRUD operations on `Climb`, set `ClimbsController` to inherit from `ProtectedController`.  I think that this will allow you to test `create` with the method that I described without having `user_id` in the permitted parameters."}}
{"actor":{"display_login":"bernardlee"}}