Guest User

Untitled

a guest
May 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. create_table "Blackoutperiods", force: :cascade do |t|
  2. t.string "title"
  3. t.string "company_name"
  4. t.datetime "start"
  5. t.datetime "end"
  6. t.datetime "created_at", null: false
  7. t.datetime "updated_at", null: false
  8. t.integer "user_id"
  9. end
  10.  
  11. class BlackoutperiodsController < ApplicationController
  12.  
  13. before_action :find_blackoutperiod, only: [:show, :edit, :update, :destroy]
  14. before_action :authenticate_user!, except: [:index, :show]
  15. before_action :authenticate_user!
  16.  
  17.  
  18. def index
  19. @blackoutperiods = Blackoutperiod.all.order("created_at DESC")
  20. end
  21.  
  22. def show
  23. @blackoutperiods = Blackoutperiod.all.order("created_at DESC")
  24. end
  25.  
  26. def new
  27. @blackoutperiod = current_user.blackoutperiods.build
  28. end
  29.  
  30. def edit
  31. end
  32. def update
  33. if @blackoutperiod.update(blackoutperiod_params)
  34. redirect_to blackoutperiods_path(@blackoutperiod)
  35. else
  36. render 'edit'
  37. end
  38. end
  39.  
  40. def create
  41. @blackoutperiod = current_user.blackoutperiods.build(blackoutperiod_params)
  42. if @blackoutperiod.save
  43. redirect_to blackoutperiods_path
  44. else
  45. render 'new'
  46. end
  47. end
  48.  
  49. def blackoutperiod_params
  50. params.require(:blackoutperiod).permit(:title, :company_name, :start, :end, :user_id)
  51. end
  52.  
  53. def find_blackoutperiod
  54. @blackoutperiod = Blackoutperiod.find(params[:id])
  55. end
  56.  
  57.  
  58. end
  59.  
  60. <%= simple_form_for @blackoutperiod do |f| %>
  61. <%= f.input :title, label: "Title" %>
  62. <%= f.input :company_name, label: "Company name" %>
  63. <%= f.input :start, label: "Start" %>
  64. <%= f.input :end, label: "End" %>
  65. <%= f.button :submit, :class => 'btn-custom' %>
  66. <% end %>
  67.  
  68. Rails.application.routes.draw do
  69. scope "/:locale", locale: /#{I18n.available_locales.join("|")}/ do
  70. resources :blackoutperiods
  71. root to: redirect("/%{locale}/posts", status: 302)
  72. end
  73. root to: redirect("/#{I18n.default_locale}", status: 302), as: :redirected_root
  74. get "/*path", to: redirect("/#{I18n.default_locale}/%{path}", status: 302), constraints: {path: /(?!(#{I18n.available_locales.join("|")})/).*/}, format: false
  75. end
  76.  
  77. class Blackoutperiod < ApplicationRecord
  78. belongs_to :user
  79. belongs_to :resource
  80. belongs_to :entreprise
  81. end
  82.  
  83. Processing by BlackoutperiodsController#create as HTML
  84. Parameters: {"utf8"=>"✓", "authenticity_token"=>"XXXXXXXXXXX", "blackoutperiod"=>{"title"=>"2018", "company_name"=>"ABC", "start(1i)"=>"2018", "start(2i)"=>"5", "start(3i)"=>"23", "start(4i)"=>"01", "start(5i)"=>"26", "end(1i)"=>"2018", "end(2i)"=>"5", "end(3i)"=>"23", "end(4i)"=>"01", "end(5i)"=>"26"}, "commit"=>"Create Blackoutperiod", "locale"=>"en"}
  85. User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 12], ["LIMIT", 1]]
  86. (0.1ms) begin transaction
  87. (0.1ms) rollback transaction
  88. Rendering blackoutperiods/new.html.erb within layouts/application
  89. Rendered blackoutperiods/_form.html.erb (17.8ms)
  90. Rendered blackoutperiods/new.html.erb within layouts/application (37.3ms)
  91. Completed 200 OK in 574ms (Views: 515.9ms | ActiveRecord: 0.6ms)
Add Comment
Please, Sign In to add comment