Guest User

Untitled

a guest
Jan 14th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. # coding: utf-8
  2. class UsersController < ApplicationController
  3.  
  4. def new
  5. @user = User.new
  6. end
  7.  
  8. def create
  9. @user = User.new(user_params)
  10. if @user.save
  11. flash[:success] = "registing user data"
  12. redirect_to '/'
  13. else
  14. flash[:danger] = "invalid info"
  15. redirect_to '/signup'
  16. end
  17. end
  18.  
  19. private
  20. def user_params
  21. params.require(:user).permit(:user_name, :email, :password, :password_confirmation)
  22. end
  23.  
  24. <h1>Add</h1>
  25. </div>
  26. <%= javascript_pack_tag 'new' %>
  27. <div>
  28.  
  29. <template>
  30. <form accept-charset="UTF-8">
  31. <input type="text" v-model="username" placeholder="username">
  32. <input type="text" v-model="email" placeholder="email">
  33. <input type="password" v-model="password" placeholder="password">
  34. <input type="password" v-model="password_confirm" placeholder="password(confirm)">
  35. <button type="submit" v-on:click="sendForm">send</button>
  36. </form>
  37. </template>
  38.  
  39. <script>
  40. import axios from 'axios';
  41.  
  42. const token = document.getElementsByName("csrf-token")[0].getAttribute("content");
  43. axios.defaults.headers.common["X-CSRF-Token"] = token;
  44. axios.defaults.headers.common["Content-Type"] = "application/json";
  45. axios.defaults.headers.common["charset"] = "utf-8";
  46. axios.defaults.headers.common["X-Requested-With"] = "XMLHttpRequest";
  47.  
  48. export default {
  49. data: function() {
  50. return {
  51. username: "",
  52. email: "",
  53. password: "",
  54. password_confirm: ""
  55. }
  56. },
  57. methods: {
  58. sendForm: function(e){
  59. axios.post("/signup", {
  60. "user": {
  61. "user_name": this.username,
  62. "email": this.email,
  63. "password": this.password,
  64. "password_confirmation": this.password_confirm,
  65. }
  66. })
  67. .then(response => {
  68. })
  69. .catch(response => {
  70. });
  71. }
  72. }
  73. }
  74. </script>
  75.  
  76. import Vue from 'vue';
  77. import New from '../new.vue';
  78. import TurbolinksAdapter from 'vue-turbolinks';
  79.  
  80. Vue.use(TurbolinksAdapter);
  81.  
  82. document.addEventListener('turbolinks:load', () => {
  83. const el = document.body.appendChild(document.createElement('new'));
  84. const new_ = new Vue({
  85. el,
  86. render: h => h(New)
  87. });
  88.  
  89. console.log('/new page');
  90. });
Add Comment
Please, Sign In to add comment