Многочисленные сбои после установки I18n в Ruby - PullRequest
0 голосов
/ 23 мая 2018

Поскольку я установил I18n, некоторые из моих форм больше не работают.Я понял, что они являются теми, которые включают ввод даты и времени.Есть ли шаг, который я должен добавить / изменить в моей настройке?Я пытаюсь создать запись в моей модели Blackoutperiods.

Моя модель Blackoutperiod выглядит следующим образом:

  create_table "Blackoutperiods", force: :cascade do |t|
    t.string "title"
    t.string "company_name"
    t.datetime "start"
    t.datetime "end"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.integer "user_id"
  end

Мой контроллер выглядит следующим образом:

class BlackoutperiodsController < ApplicationController

  before_action :find_blackoutperiod, only: [:show, :edit, :update, :destroy]
  before_action :authenticate_user!, except: [:index, :show]
  before_action :authenticate_user!


  def index
    @blackoutperiods = Blackoutperiod.all.order("created_at DESC")
  end

  def show
    @blackoutperiods = Blackoutperiod.all.order("created_at DESC")
  end

  def new
    @blackoutperiod = current_user.blackoutperiods.build
  end

  def edit
  end
  def update
    if @blackoutperiod.update(blackoutperiod_params)
      redirect_to blackoutperiods_path(@blackoutperiod)
    else
      render 'edit'
    end
  end

  def create
    @blackoutperiod = current_user.blackoutperiods.build(blackoutperiod_params)
    if @blackoutperiod.save
      redirect_to blackoutperiods_path
    else
      render 'new'
    end
  end

  def blackoutperiod_params
    params.require(:blackoutperiod).permit(:title, :company_name, :start, :end, :user_id)
  end

  def find_blackoutperiod
    @blackoutperiod = Blackoutperiod.find(params[:id])
  end


end

my _form.html.erb выглядит так:

<%= simple_form_for @blackoutperiod do |f| %>
  <%= f.input :title, label: "Title" %>
  <%= f.input :company_name, label: "Company name" %>
  <%= f.input :start, label: "Start" %>
  <%= f.input :end, label: "End" %>
  <%= f.button :submit, :class => 'btn-custom' %>
<% end %>

Мои маршруты выглядят так:

Rails.application.routes.draw do
scope "/:locale", locale: /#{I18n.available_locales.join("|")}/ do
    resources :blackoutperiods
    root to: redirect("/%{locale}/posts", status: 302)
  end
  root to: redirect("/#{I18n.default_locale}", status: 302), as: :redirected_root
  get "/*path", to: redirect("/#{I18n.default_locale}/%{path}", status: 302), constraints: {path: /(?!(#{I18n.available_locales.join("|")})\/).*/}, format: false
end

мои модели выглядят так:

class Blackoutperiod < ApplicationRecord
  belongs_to :user
  belongs_to :resource
  belongs_to :entreprise
end

У меня

 class Entreprise < ApplicationRecord
    belongs_to :user
    has_many :blackoutperiods
    end

И пользователь has_many blackoutperiodsконечно.У меня следующая ошибка:

Processing by BlackoutperiodsController#create as HTML
  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"}
  User Load (0.4ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ?  [["id", 12], ["LIMIT", 1]]
   (0.1ms)  begin transaction
   (0.1ms)  rollback transaction
  Rendering blackoutperiods/new.html.erb within layouts/application
  Rendered blackoutperiods/_form.html.erb (17.8ms)
  Rendered blackoutperiods/new.html.erb within layouts/application (37.3ms)
Completed 200 OK in 574ms (Views: 515.9ms | ActiveRecord: 0.6ms)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...