【问题标题】:Heroku records a fixnum instead of a stringHeroku 记录一个固定数字而不是一个字符串
【发布时间】:2018-08-12 06:05:47
【问题描述】:

在本地,它按预期记录一个字符串,在 Heroku 上它记录一个 fixnum...

用户可以创建愿望并选择他想看音乐会的区域。如果音乐会符合他的愿望,以便收到电子邮件。

我的application_helper.rb 中有一个哈希作为常量

  DEPARTMENTS = {
    "01" => "Ain",
    "02" => "Aisne",
    "03" => "Allier"
    #........
}

我在wanted_concerts_controller.rb 中的创建方法是这样的

def create
    @wanted_concert = WantedConcert.new(wanted_concerts_params)
    @wanted_concert.user_id = current_user.id
    if @wanted_concert.save!
      redirect_to wanted_concerts_path, notice: "Ton souhait est bien enregistré"
    else
      render :new , alert: "Oups recommence!"
    end
  end

private 

  def wanted_concerts_params
    params.require(:wanted_concert).permit(:department, :user_id)
  end

the new.html.erb文件中我可以实现我的愿望

<%= simple_form_for(@wanted_concert) do |f| %>
    <%= f.input :department, prompt: "Choisi une région", label: false, collection: ApplicationHelper::DEPARTMENTS.map { |k, v| v } %>
    <%= f.submit "Valider", class: "btn btn-success" %>
<% end %>

这是我的index.html.erb 显示愿望的地方

    <li> <%= wanted.department %> <%= link_to "Supprimer", wanted_concert_path(wanted), method: :delete %></li>
  <% end %>

如果我选择例如本地Ain 索引显示Ain

如果选择了在 Heroku 上 Ain 它显示 0

所以在 Heroku 控制台上我做了:

irb(main):004:0> c = WantedConcert.last
D, [2018-03-04T13:31:54.314672 #4] DEBUG -- :   WantedConcert Load (1.3ms)  SELECT  "wanted_concerts".* FROM "wanted_concerts" ORDER BY "wanted_concerts"."id" DESC LIMIT $1  [["LIMIT", 1]]
=> #<WantedConcert id: 21, department: 0, user_id: 1, created_at: "2018-03-04 13:02:16", updated_at: "2018-03-04 13:02:16">
irb(main):005:0> c.department.class
=> Integer
irb(main):006:0>

【问题讨论】:

    标签: ruby ruby-on-rails-4 heroku ruby-on-rails-5


    【解决方案1】:

    我找到了帮助。 我犯了一个顽皮的错误,我在旧迁移中重命名了一个字段,而不是在新迁移中重命名...... 因此,这可能会帮助面临类似错误的人...

    【讨论】:

      猜你喜欢
      • 2019-08-27
      • 1970-01-01
      • 1970-01-01
      • 2011-03-10
      • 2021-12-23
      • 2023-03-16
      • 2013-08-12
      • 2015-05-10
      • 1970-01-01
      相关资源
      最近更新 更多