Shubhi Agarwal
Shubhi Agarwal

Reputation: 21

Results outputting to console rather then browser.

This code is working correctly. The problem is everything is getting printed to the console. I want to show it on the browser. How to do that? Do I need a template called create.html.erb. How to access the variables and basically the whole controller code in the view? Please help!!

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

Upvotes: 0

Views: 67

Answers (1)

bento
bento

Reputation: 2099

Yes, you would create an create.html.erb and can access all Controller Instance variables like @entity or @var from there.

I'd recommend looking at the output from a generate scaffold call to get an example how this works, e.g. by calling it in a new rails app:

rails new tryout
cd tryout
rails generate scaffold User name:string email:string

and then look at the generated controller and view templates.

Upvotes: 1

Related Questions