Ruby on Rails变形问题 [英] Ruby on Rails Inflection Issue

查看:74
本文介绍了Ruby on Rails变形问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ruby on Rails为我玩的游戏创建网站.

I am using Ruby on Rails to create a website for a game I play.

我有一个User模型和一个Starbase模型.我尝试建立的关系就像这样

I have a User model and a Starbase model. The relationship I am trying to setup is like so

class User < ActiveRecord::Base
  has_many :starbases
end

class Starbase < ActiveRecord::Base
  belongs_to :user
end

但是,当我打开脚本/控制台并尝试访问用户starbases时,却出现了错误:NameError: uninitialized constant User::Starbasis.

However when I open script/console and try to access the users starbases it gives me an error: NameError: uninitialized constant User::Starbasis.

似乎是拐点的问题,并且导轨不能正确地复数星基.

It seems as if it is a problem with inflection and rails is not pluralizing starbase correct.

我尝试将其添加到intializers文件夹中的inflections.rb:

I have tried adding this to the inflections.rb in the intializers folder:

ActiveSupport::Inflector.inflections do |inflect|
  inflect.plural 'starbase', 'starbases'
end

,但仍然不能解决问题.谁能提供有关如何使其正常工作的建议?

but it still does not solve the issue. Could anyone give advice on how to get this working?

欢呼

Eef

推荐答案

您是否尝试过为反曲率添加一行(即单数"):

Have you tried adding a line for the inverse inflection (i.e. 'singular'):

 inflect.singular "starbases", "starbase"

我在控制台中尝试了您的示例,而单数化导致了问题,而不是相反.我不确定这是否可以解决其他问题(例如路线),但是应该可以解决简单的问题(我认为).

I tried your example in my console and it was the singularization that caused problems, not the other way around. I'm not sure if this fixes other issues (like routes), but it should fix the simple stuff (I think).

这篇关于Ruby on Rails变形问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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