我是 Rails 的新手。我希望如果一个人在表单上输入“entity1”(或ENTITIES
下面代码中调用的列表中存在的其他实体),表单应该显示其关系。检查实体是否包含在实体列表中的任务成功,我无法理解如何打印已调用的关系RELATION_SHIPS
。我试过了:
#puts EntityList::RELATION_SHIPS[params[:user][:entity_name]]
但它给了我一个错误,说模板丢失或RELATION_SHIPS
无法识别。我该如何解决这个问题?
#users_controller.rb
class EntityList
ENTITIES = ['entity1','entity2','entity3']
#entity1 = {:name => 'Entity One',:position => 1 :relationships => 'entity2', 'entity4'}
RELATION_SHIPS = {:entity1 => "entity2", :entity2 => "entity3"}
end
class UsersController < ApplicationController
layout 'admin'
#require File.expand_path('././myconfig') #=> C:/ruby/require/expand_path/ok.rb loaded
def new
@user = User.new
end
def create
if EntityList::ENTITIES.include?(params[:user][:entity_name])
flash[:notice] = "The entity you entered is valid!!"
redirect_to(:action => "helloworld")
#puts EntityList::RELATION_SHIPS[params[:user][:entity_name]]
else
redirect_to(:action => "SorryPage")
end
end
end