此代码工作正常。问题是所有内容都打印到控制台。我想在浏览器上显示它。怎么做?我需要一个名为 create.html.erb 的模板吗?如何访问视图中的变量和基本上整个控制器代码?请帮忙!!
require File.join(Rails.root, 'config/myconfig')
puts Rails.root
class UsersController < ApplicationController
layout 'admin'
#require File.expand_path('././myconfig') #=> C:/ruby/require/expand_path/ok.rb loaded
def list
@users = User.all
end
def new
@user = User.new
end
def create
if EntityList::ENTITIES.include?(params[:user][:entity_name])
puts " Entered entity is: "
@entity = params[:user][:entity_name]
@var = EntityList::RELATION_SHIPS[@entity.to_sym]
puts "Entered entity is related to"
if(@var.nil?)
#do nothing
else
puts @var
checking(@var)
end
#@var.split(" ")
#@len = @var.length
#puts @var[0]
#puts @var[1]
#puts @var[1]
#@var.each {|@var| puts @var}
#for index in 0 ... @var.size
# puts EntityList::RELATION_SHIPS[@var[index].to_sym]
# end
# @var.each_with_index {|val, index| puts "#{val} => #{index}" }
#@var2= EntityList::RELATION_SHIPS[@var.to_sym]
#puts "Entity2 is related to"
#puts @var2
flash[:notice] = "The entity you entered is valid!!"
puts "Before Redirection"
redirect_to(:action => "helloworld")
puts "After redirection"
puts "done"
else
redirect_to(:action => "SorryPage")
end
end
def checking(array)
array.split(" ")
for index2 in 0 ... array.size
if EntityList::RELATION_SHIPS[array[index2].to_sym].nil?
# do nothing
else
puts EntityList::RELATION_SHIPS[array[index2].to_sym]
some = EntityList::RELATION_SHIPS[array[index2].to_sym]
checking(some)
end
end
end
end