私は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