使用带有 form_tag 且无模型的 country_select gem [英] Using country_select gem with form_tag and no model

查看:52
本文介绍了使用带有 form_tag 且无模型的 country_select gem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Rails 4 的表单标签中使用 country_select gem:

I am using the country_select gem in Rails 4 in a form tag:

<%= form_tag(@url, method: :post, class: "form-horizontal") do %>
    <div class="form-group">
      <%= label_tag(:country_code, "Country code") %>
      <%= country_select :country_code, @country_code, class: "form-control" %>
    </div><% end %>

我收到以下错误.

undefined method `NZ' for "NZ":String

这是一个安静的异常错误,我没有发现 country_select gem 的任何其他实例.rails 应用程序没有数据库并且正在与外部数据库通信,因此该应用程序中没有模型.有人建议我使用 Open Struct 来解决这个问题.但是,我想知道有没有人知道更快的解决方法?表单正在获取数据库中的数据!

This is a quiet unusual error and I have not found any other instances of it for the country_select gem. The rails application does not have a database and is communicating to an external database so there are no models in this application. I have been suggested to use Open Struct to get around this issue. However, I am wondering does anyone know of a quicker fix? The form is picking up the data in the database though!

推荐答案

问题在于我没有模型.我需要使用帮助我模拟对象的 OpenStruct 数据结构.您可以阅读有关它的更多信息 这里

The issue was with the fact that I had no model. I needed to use the OpenStruct data structure which helped me to simulate objects. You can read more about it here

这篇关于使用带有 form_tag 且无模型的 country_select gem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆