【问题标题】:NoMethodError in Item_categories#newItem_categories 中的 NoMethodError#new
【发布时间】:2016-08-31 15:44:42
【问题描述】:

我有下一个问题:

显示 /Users/felipevelasquez/Desktop/APPS/meetrico2/meetrico-production/app/views/item_categories/_form.html.haml 其中第 40 行提出:

用于#的未定义方法`cupon_code'

提取的源代码(第 40 行附近):

37:   %p
38:     = f.label :cupon_code, "Codigo de cupon"
39:     %br/
40:     = f.text_field :cupon_code
41:   %p.columns
42:     = f.label :num_tables, "No. Prod:"
43:     %br/

模板包含的痕迹:app/views/item_categories/new.html.haml

Rails.root:/Users/felipevelasquez/Desktop/APPS/meetrico2/meetrico-production 应用程序跟踪 |框架跟踪 |全程跟踪

app/views/item_categories/_form.html.haml:40:in block in _app_views_item_categories__form_html_haml__1368949097161944936_70115358072760' app/views/item_categories/_form.html.haml:1:in_app_views_item_categories__form_html_haml__1368949097161944936_70115358072760' app/views/item_categories/new.html.haml:4:in _app_views_item_categories_new_html_haml__3526667596950049714_70115303712400' config/initializers/quiet_assets.rb:13:incall_with_quiet_assets'

请求

参数:

显示会话转储

显示环境转储 回应

标题:

我在我的数据库 cupon_code 中创建了该字段,这是我的架构:

create_table "transactions", :force => true do |t|
    t.integer  "order_id"
    t.string   "action"
    t.integer  "amount"
    t.boolean  "success"
    t.string   "authorization"
    t.string   "message"
    t.text     "params"
    t.datetime "created_at",    :null => false
    t.datetime "updated_at",    :null => false
    t.integer  "cupon_code"

谁能看出问题出在哪里?

这是孔的形式:

= form_for @item_category, html: { class: 'upload-file-or-text'} do |f|
  %p
    = f.label :coworking_space, "Coworking Space"
    %br/
    = select_tag "item_category[coworking_space_id]", options_from_collection_for_select(@coworking_spaces, "id", "name", @item_category.coworking_space_id)
  %p
    = f.label :name, "Nombre"
    %br/
    = f.text_field :name, :required=>"required",:title=>"Este campo es obligatorio"
  %p.columns
    = f.label :image_text_url, "Url de Imagen o Icono"
    %br/
    = f.text_area :image_text_url, :size => "40x4", class: 'image-text'
  %p.columns
    = f.label :image_file, "O sube una imagen"
    - if @item_category.image_file?
      %br/
      = image_tag @item_category.image_url, class: 'image-thumb'
      %label
        = f.check_box :remove_image_file, class: 'remove-ckeck'
        Eliminar image?
    %br/
    = f.file_field :image_file, class: 'image-file'
  %p.alert-message.hide
    Debe elegir alguna de estas opciones
  %p
    = f.label :description, "Descripción"
    %br/
    = f.text_area :description, :size => "40x4"
  %p
    = f.label :notification_body, "Cuerpo de Notificacion"
    %br/
    = f.text_area :notification_body, :size => "40x4"
  %p
    = f.check_box :promo_header
    Línea de Producto de la cabecera
  %p
    = f.label :cupon_code, "Codigo de cupon"
    %br/
    = f.text_field :cupon_code
  %p.columns
    = f.label :num_tables, "No. Prod:"
    %br/
    = f.text_field :num_tables
  %p.columns
    = f.label :reserved, "Reservas:"
    %br/
    = f.text_field :reserved
  %p
    = f.label :normal_price, t(:normal_sale_price)
    %label
      = "en #{@item_category.coworking_space.city.currency.name rescue " "}"
    %br/
    = f.text_field :normal_price
  %p.columns
    = f.label :green, "Green:"
    %label
      = "en #{@item_category.coworking_space.city.currency.name rescue " "}"
    %br/
    = f.text_field :green
  %p.columns
    = f.label :green, "Yellow:"
    %label
      = "en #{@item_category.coworking_space.city.currency.name rescue " "}"
    %br/
    = f.text_field :yellow
  %p.columns
    = f.label :green, "Red:"
    %label
      = "en #{@item_category.coworking_space.city.currency.name rescue " "}"
    %br/
    = f.text_field :red
  %p
    = f.label :target_url, t(:target_url)
    %br/
    = f.text_field :target_url
  %p= f.submit

【问题讨论】:

  • 你能把整个表格贴出来吗?
  • 您是否创建并运行了迁移以添加 cupon 代码?
  • 是的,我做到了,在表交易中。这就是我所做的: rails generate migration AddCuponCodeColumnToTransactions cupon_code:integer
  • 我确实张贴了俄语版的孔,谢谢!

标签: ruby-on-rails ruby database nomethoderror


【解决方案1】:

事务是@item_category 的一部分吗? 对象@item_category 中的所有属性仅在form_for 中可用。如果事务的属性未设置为可从@item_category 访问,它将不起作用。

希望对你有帮助!

【讨论】:

  • 所以我必须在属性中说交易属于_to item category?
  • 是的...如果交易属于商品类别,则在交易模型中应为belongs_to。最后,如果项目类别有很多交易,它应该在项目类别模型中显式(has_many :transactions
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多