Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uninitialized constant error (Ruby Sinatra) #84

Open
donchev1 opened this issue Nov 20, 2016 · 0 comments
Open

uninitialized constant error (Ruby Sinatra) #84

donchev1 opened this issue Nov 20, 2016 · 0 comments

Comments

@donchev1
Copy link

Hey guys, I am quite new to programming and I can't call a certain method in file from a different file.
I am using Sinatra and I am trying to display some input to a browser. According to my practical sheets from uni this is supposed to display the number from source file to the browser. It works for the command line window but not when I am calling it from the layout.rb file. It is giving me uninitialized constant error. Please Help!

mainfile.rb

require "#{File.dirname(FILE)}/source"
require 'sinatra'
get '/' do
home :erb
end

source.rb

module OXO_Game
class Game
attr_reader :input, :output
attr_writer :input, :output
def initialize(input, output)
@input = input
@output = output
end
def student_id
@student_id = "51235134"
end
end
end

layout.rb

<% require "#{File.dirname(__FILE__)}/source" %>
                <% module OXO_Game %>

                <% @input = STDIN %>

            	<% @output = STDOUT %>

            	<% g = Game.new(@input, @output) %>

                    <% g.student_id %>

            	<% end %>

<%= yield %>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant