{"action":"opened","number":407,"pull_request":{"url":"https://api.github.com/repos/rails/jquery-ujs/pulls/407","id":31064378,"html_url":"https://github.com/rails/jquery-ujs/pull/407","diff_url":"https://github.com/rails/jquery-ujs/pull/407.diff","patch_url":"https://github.com/rails/jquery-ujs/pull/407.patch","issue_url":"https://api.github.com/repos/rails/jquery-ujs/issues/407","number":407,"state":"open","locked":false,"title":"Extract csrfToken and csrfParam to allow external use","user":{"login":"monkbroc","id":1919681,"avatar_url":"https://avatars.githubusercontent.com/u/1919681?v=3","gravatar_id":"","url":"https://api.github.com/users/monkbroc","html_url":"https://github.com/monkbroc","followers_url":"https://api.github.com/users/monkbroc/followers","following_url":"https://api.github.com/users/monkbroc/following{/other_user}","gists_url":"https://api.github.com/users/monkbroc/gists{/gist_id}","starred_url":"https://api.github.com/users/monkbroc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monkbroc/subscriptions","organizations_url":"https://api.github.com/users/monkbroc/orgs","repos_url":"https://api.github.com/users/monkbroc/repos","events_url":"https://api.github.com/users/monkbroc/events{/privacy}","received_events_url":"https://api.github.com/users/monkbroc/received_events","type":"User","site_admin":false},"body":"I would like to use the CSRF token independently from the jQuery UJS library.\r\n\r\nRather than copy-pasting the jQuery snippet `$('meta[name=csrf-token]').attr('content')` into my own code I propose to extract it to its own method so I can refer to it like this: `$.rails.csrfToken()`\r\n\r\nMy use case is to render client-side templates that include forms. This way I can render the CSRF at the same time as the other content:\r\n\r\n```erb\r\n<div class=\"modal fade\">\r\n  <div class=\"modal-dialog\">\r\n    <div class=\"modal-content\">\r\n      <form class=\"edit_comment\" action=\"/comments/<%= @id %>\" accept-charset=\"UTF-8\" method=\"post\">\r\n        <input name=\"utf8\" type=\"hidden\" value=\"✓\">\r\n        <input name=\"_method\" type=\"hidden\" value=\"patch\">\r\n        <input type=\"hidden\" name=\"<%= $.rails.csrfParam() %>\" value=\"<%= $.rails.csrfToken() %>\">\r\n        <div class=\"modal-header\">\r\n          <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-label=\"Close\"><span aria-hidden=\"true\">&times;</span></button>\r\n          <h4 class=\"modal-title\">Edit Comment</h4>\r\n        </div>\r\n        <div class=\"modal-body\">\r\n          <textarea class=\"form-control\" rows=\"5\" name=\"comment[body]\" id=\"comment_body\"><%= @body %></textarea>\r\n        </div>\r\n        <div class=\"modal-footer\">\r\n          <button type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\">Cancel</button>\r\n          <button type=\"submit\" class=\"btn btn-primary\">Update</button>\r\n        </div>\r\n      </form>\r\n    </div>\r\n  </div>\r\n</div>\r\n```","created_at":"2015-03-12T18:29:01Z","updated_at":"2015-03-12T18:29:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/rails/jquery-ujs/pulls/407/commits","review_comments_url":"https://api.github.com/repos/rails/jquery-ujs/pulls/407/comments","review_comment_url":"https://api.github.com/repos/rails/jquery-ujs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rails/jquery-ujs/issues/407/comments","statuses_url":"https://api.github.com/repos/rails/jquery-ujs/statuses/96f4474065df7a9afbebd36151aa66ee9e57ac25","head":{"label":"monkbroc:master","ref":"master","sha":"96f4474065df7a9afbebd36151aa66ee9e57ac25","user":{"login":"monkbroc","id":1919681,"avatar_url":"https://avatars.githubusercontent.com/u/1919681?v=3","gravatar_id":"","url":"https://api.github.com/users/monkbroc","html_url":"https://github.com/monkbroc","followers_url":"https://api.github.com/users/monkbroc/followers","following_url":"https://api.github.com/users/monkbroc/following{/other_user}","gists_url":"https://api.github.com/users/monkbroc/gists{/gist_id}","starred_url":"https://api.github.com/users/monkbroc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monkbroc/subscriptions","organizations_url":"https://api.github.com/users/monkbroc/orgs","repos_url":"https://api.github.com/users/monkbroc/repos","events_url":"https://api.github.com/users/monkbroc/events{/privacy}","received_events_url":"https://api.github.com/users/monkbroc/received_events","type":"User","site_admin":false},"repo":{"id":32093282,"name":"jquery-ujs","full_name":"monkbroc/jquery-ujs","owner":{"login":"monkbroc","id":1919681,"avatar_url":"https://avatars.githubusercontent.com/u/1919681?v=3","gravatar_id":"","url":"https://api.github.com/users/monkbroc","html_url":"https://github.com/monkbroc","followers_url":"https://api.github.com/users/monkbroc/followers","following_url":"https://api.github.com/users/monkbroc/following{/other_user}","gists_url":"https://api.github.com/users/monkbroc/gists{/gist_id}","starred_url":"https://api.github.com/users/monkbroc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monkbroc/subscriptions","organizations_url":"https://api.github.com/users/monkbroc/orgs","repos_url":"https://api.github.com/users/monkbroc/repos","events_url":"https://api.github.com/users/monkbroc/events{/privacy}","received_events_url":"https://api.github.com/users/monkbroc/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/monkbroc/jquery-ujs","description":"Ruby on Rails unobtrusive scripting adapter for jQuery","fork":true,"url":"https://api.github.com/repos/monkbroc/jquery-ujs","forks_url":"https://api.github.com/repos/monkbroc/jquery-ujs/forks","keys_url":"https://api.github.com/repos/monkbroc/jquery-ujs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/monkbroc/jquery-ujs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/monkbroc/jquery-ujs/teams","hooks_url":"https://api.github.com/repos/monkbroc/jquery-ujs/hooks","issue_events_url":"https://api.github.com/repos/monkbroc/jquery-ujs/issues/events{/number}","events_url":"https://api.github.com/repos/monkbroc/jquery-ujs/events","assignees_url":"https://api.github.com/repos/monkbroc/jquery-ujs/assignees{/user}","branches_url":"https://api.github.com/repos/monkbroc/jquery-ujs/branches{/branch}","tags_url":"https://api.github.com/repos/monkbroc/jquery-ujs/tags","blobs_url":"https://api.github.com/repos/monkbroc/jquery-ujs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/monkbroc/jquery-ujs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/monkbroc/jquery-ujs/git/refs{/sha}","trees_url":"https://api.github.com/repos/monkbroc/jquery-ujs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/monkbroc/jquery-ujs/statuses/{sha}","languages_url":"https://api.github.com/repos/monkbroc/jquery-ujs/languages","stargazers_url":"https://api.github.com/repos/monkbroc/jquery-ujs/stargazers","contributors_url":"https://api.github.com/repos/monkbroc/jquery-ujs/contributors","subscribers_url":"https://api.github.com/repos/monkbroc/jquery-ujs/subscribers","subscription_url":"https://api.github.com/repos/monkbroc/jquery-ujs/subscription","commits_url":"https://api.github.com/repos/monkbroc/jquery-ujs/commits{/sha}","git_commits_url":"https://api.github.com/repos/monkbroc/jquery-ujs/git/commits{/sha}","comments_url":"https://api.github.com/repos/monkbroc/jquery-ujs/comments{/number}","issue_comment_url":"https://api.github.com/repos/monkbroc/jquery-ujs/issues/comments{/number}","contents_url":"https://api.github.com/repos/monkbroc/jquery-ujs/contents/{+path}","compare_url":"https://api.github.com/repos/monkbroc/jquery-ujs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/monkbroc/jquery-ujs/merges","archive_url":"https://api.github.com/repos/monkbroc/jquery-ujs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/monkbroc/jquery-ujs/downloads","issues_url":"https://api.github.com/repos/monkbroc/jquery-ujs/issues{/number}","pulls_url":"https://api.github.com/repos/monkbroc/jquery-ujs/pulls{/number}","milestones_url":"https://api.github.com/repos/monkbroc/jquery-ujs/milestones{/number}","notifications_url":"https://api.github.com/repos/monkbroc/jquery-ujs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/monkbroc/jquery-ujs/labels{/name}","releases_url":"https://api.github.com/repos/monkbroc/jquery-ujs/releases{/id}","created_at":"2015-03-12T18:08:20Z","updated_at":"2015-03-12T18:23:10Z","pushed_at":"2015-03-12T18:23:10Z","git_url":"git://github.com/monkbroc/jquery-ujs.git","ssh_url":"git@github.com:monkbroc/jquery-ujs.git","clone_url":"https://github.com/monkbroc/jquery-ujs.git","svn_url":"https://github.com/monkbroc/jquery-ujs","homepage":"","size":694,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rails:master","ref":"master","sha":"519aad962496497870621e5b6afe2a727a28839d","user":{"login":"rails","id":4223,"avatar_url":"https://avatars.githubusercontent.com/u/4223?v=3","gravatar_id":"","url":"https://api.github.com/users/rails","html_url":"https://github.com/rails","followers_url":"https://api.github.com/users/rails/followers","following_url":"https://api.github.com/users/rails/following{/other_user}","gists_url":"https://api.github.com/users/rails/gists{/gist_id}","starred_url":"https://api.github.com/users/rails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails/subscriptions","organizations_url":"https://api.github.com/users/rails/orgs","repos_url":"https://api.github.com/users/rails/repos","events_url":"https://api.github.com/users/rails/events{/privacy}","received_events_url":"https://api.github.com/users/rails/received_events","type":"Organization","site_admin":false},"repo":{"id":494159,"name":"jquery-ujs","full_name":"rails/jquery-ujs","owner":{"login":"rails","id":4223,"avatar_url":"https://avatars.githubusercontent.com/u/4223?v=3","gravatar_id":"","url":"https://api.github.com/users/rails","html_url":"https://github.com/rails","followers_url":"https://api.github.com/users/rails/followers","following_url":"https://api.github.com/users/rails/following{/other_user}","gists_url":"https://api.github.com/users/rails/gists{/gist_id}","starred_url":"https://api.github.com/users/rails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails/subscriptions","organizations_url":"https://api.github.com/users/rails/orgs","repos_url":"https://api.github.com/users/rails/repos","events_url":"https://api.github.com/users/rails/events{/privacy}","received_events_url":"https://api.github.com/users/rails/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rails/jquery-ujs","description":"Ruby on Rails unobtrusive scripting adapter for jQuery","fork":false,"url":"https://api.github.com/repos/rails/jquery-ujs","forks_url":"https://api.github.com/repos/rails/jquery-ujs/forks","keys_url":"https://api.github.com/repos/rails/jquery-ujs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rails/jquery-ujs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rails/jquery-ujs/teams","hooks_url":"https://api.github.com/repos/rails/jquery-ujs/hooks","issue_events_url":"https://api.github.com/repos/rails/jquery-ujs/issues/events{/number}","events_url":"https://api.github.com/repos/rails/jquery-ujs/events","assignees_url":"https://api.github.com/repos/rails/jquery-ujs/assignees{/user}","branches_url":"https://api.github.com/repos/rails/jquery-ujs/branches{/branch}","tags_url":"https://api.github.com/repos/rails/jquery-ujs/tags","blobs_url":"https://api.github.com/repos/rails/jquery-ujs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rails/jquery-ujs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rails/jquery-ujs/git/refs{/sha}","trees_url":"https://api.github.com/repos/rails/jquery-ujs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rails/jquery-ujs/statuses/{sha}","languages_url":"https://api.github.com/repos/rails/jquery-ujs/languages","stargazers_url":"https://api.github.com/repos/rails/jquery-ujs/stargazers","contributors_url":"https://api.github.com/repos/rails/jquery-ujs/contributors","subscribers_url":"https://api.github.com/repos/rails/jquery-ujs/subscribers","subscription_url":"https://api.github.com/repos/rails/jquery-ujs/subscription","commits_url":"https://api.github.com/repos/rails/jquery-ujs/commits{/sha}","git_commits_url":"https://api.github.com/repos/rails/jquery-ujs/git/commits{/sha}","comments_url":"https://api.github.com/repos/rails/jquery-ujs/comments{/number}","issue_comment_url":"https://api.github.com/repos/rails/jquery-ujs/issues/comments{/number}","contents_url":"https://api.github.com/repos/rails/jquery-ujs/contents/{+path}","compare_url":"https://api.github.com/repos/rails/jquery-ujs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rails/jquery-ujs/merges","archive_url":"https://api.github.com/repos/rails/jquery-ujs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rails/jquery-ujs/downloads","issues_url":"https://api.github.com/repos/rails/jquery-ujs/issues{/number}","pulls_url":"https://api.github.com/repos/rails/jquery-ujs/pulls{/number}","milestones_url":"https://api.github.com/repos/rails/jquery-ujs/milestones{/number}","notifications_url":"https://api.github.com/repos/rails/jquery-ujs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rails/jquery-ujs/labels{/name}","releases_url":"https://api.github.com/repos/rails/jquery-ujs/releases{/id}","created_at":"2010-01-29T20:18:24Z","updated_at":"2015-03-11T15:28:32Z","pushed_at":"2014-12-29T21:11:07Z","git_url":"git://github.com/rails/jquery-ujs.git","ssh_url":"git@github.com:rails/jquery-ujs.git","clone_url":"https://github.com/rails/jquery-ujs.git","svn_url":"https://github.com/rails/jquery-ujs","homepage":"","size":1730,"stargazers_count":2094,"watchers_count":2094,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":414,"mirror_url":null,"open_issues_count":51,"forks":414,"open_issues":51,"watchers":2094,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rails/jquery-ujs/pulls/407"},"html":{"href":"https://github.com/rails/jquery-ujs/pull/407"},"issue":{"href":"https://api.github.com/repos/rails/jquery-ujs/issues/407"},"comments":{"href":"https://api.github.com/repos/rails/jquery-ujs/issues/407/comments"},"review_comments":{"href":"https://api.github.com/repos/rails/jquery-ujs/pulls/407/comments"},"review_comment":{"href":"https://api.github.com/repos/rails/jquery-ujs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rails/jquery-ujs/pulls/407/commits"},"statuses":{"href":"https://api.github.com/repos/rails/jquery-ujs/statuses/96f4474065df7a9afbebd36151aa66ee9e57ac25"}},"merged":false,"mergeable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"commits":1,"additions":12,"deletions":4,"changed_files":1}}