I have this code. The first and second command for rails work good, but "project.todos << todo" part ruby interpreter treats like error.
NoMethodError: undefined method `todos' for nil:NilClass
How can i fix it? When i put in seeds.rb text like this, all good, but with code it not work:
#work
project = Project.create title: "Family"
todo = Todo.create text: "Buy milk", isCompleted: true
project.todos << todo
#code
require 'yaml'
yhash = YAML.load_file(File.open("#{Rails.root}/db/seeds.yml"))
yhash.each do |key, value|
value.each do |k, v|
k.each do |ke, proj|
if proj.class.name == 'String'
project = Project.create title: proj
elsif proj.class.name == 'Array'
proj.each do |todo|
i = 0
tmp = ''
todo.each do |to|
to.each do |t|
if i == 0
i = 1
elsif i == 2
i = 3
elsif i == 1
tmp = t
i = 2
elsif i == 3
if t == false
bool = 'false'
else
bool = 'true'
end
todo = Todo.create text: tmp, isCompleted: bool
project.todos << todo
i = 0
tmp = ''
end
end
end
end
end
end
end
end
Short answer
You really should change your YAML structure, it would make everything much easier.
---
projects:
- title: Family
todos:
- text: Buy milk
is_completed: true
- text: Todo2
is_completed: false
- title: Project2
todos:
- text: Todo3
is_completed: true
- text: Todo4
is_completed: false
You could parse it in a few lines :
yaml = YAML.load(File.read('test.yaml'))
yaml['projects'].each do |project|
title = project['title']
p title
# Create project here
project['todos'].each do |todo|
p todo
# Create todo here
# Add todo to project
end
end
NoMethodError
NoMethodError: undefined method 'todos' for nil:NilClass
means that the object on which todos is called (project) isn't defined.
Indeed, project isn't defined, but proj is, so you should create a Project called project first.
Naming objects
To avoid confusion :
project_name could be a string containing the project name
project_names could be an array of project names
project could be a Project object
todos could be an Array of Todos
Your code indicates that proj is used for different purposes :
project = Project.create title: proj
proj.each do |todo|
Those 2 projs should be different objects with different variable names, and should be initialized separately.
It's easy to write nested hashes in YAML, one hash could represent Projects, the other could represent Todos.
Block variables
If you create a Project instance called project inside a loop during the first iteration, it will not be available to the next iterations :
[1, 2, 3].each do |i|
if i==1
project = "my project"
end
p i
p project
end
# 1
# "my project"
# 2
# nil
# 3
# nil
If you want a project variable to be available to all iterations, you should create it outside of the loop :
project = "my project"
[1, 2, 3].each do |i|
p i
p project
end
# 1
# "my project"
# 2
# "my project"
# 3
# "my project"
Another possibility would be to use #project instead of project :
[1,2,3].each do |i|
if i==1
#project = "my project"
end
p i
p #project
end
# 1
# "my project"
# 2
# "my project"
# 3
# "my project"
case
Instead of :
if proj.class.name == 'String'
project = Project.create title: proj
elsif proj.class.name == 'Array'
You could use :
case proj
when String
# proj is a String
when Array
# proj is an Array
end
Related
I have refined the Enumerable module in a Rails controller as follows, adding one method that, as far as I know, doesn't already exist in Rails or the standard library:
module OrderedGroupBy
refine Enumerable do
def ordered_group_by(&block)
items = each
groups = []
prev = nil
loop do
begin
i = items.next
current = i.instance_eval(&block)
groups << [] if current != prev
prev = current
groups.last << i
rescue StopIteration
break
end
end
groups
end
end
end
using OrderedGroupBy
class TestController < ApplicationController
def test
numbers = ['one', 'three', 'seven', 'four', 'nine']
#groups = numbers.ordered_group_by(&:length)
end
end
Calling the controller action test results in a NoMethodError:
undefined method `ordered_group_by' for ["one", "three", "seven", "four", "nine"]:Array
To narrow down the problem, I created a standalone file with the same structure (without the Rails environment):
module OrderedGroupBy
refine Enumerable do
def ordered_group_by(&block)
items = each
groups = []
prev = nil
loop do
begin
i = items.next
current = i.instance_eval(&block)
groups << [] if current != prev
prev = current
groups.last << i
rescue StopIteration
break
end
end
groups
end
end
end
using OrderedGroupBy
class TestController < Object
def test
numbers = ['one', 'three', 'seven', 'four', 'nine']
#groups = numbers.ordered_group_by(&:length)
end
end
TestController.new.test
In this case, calling the test method has the expected result:
# => [["one"], ["three", "seven"], ["four", "nine"]]
Also, if I define the ordered_group_by method directly on Enumerable, without using refine, I can successfully call the method.
Is there some reason why this would not work as a refinement in the context of Rails, or is there something else I'm missing?
Edit: I'm using rails 5.2.0, and this is an empty project, with only rails new _ and rails generate controller Test test having been run.
I'm completely new to Ruby on Rails but I think I might be missing something obvious. I'm currently working on a webapp that scrapes auction websites. The bones of the app was created by someone else. I'm currently trying to add new website scrapes but they don't seem to be working.
I have read through some of the Nokogiri documentation, checked that the scraped information is indeed not being written to the database (the seeded URLs that are being targeted have been when I check via the rails console) and used the chrome extension CSS Selector Tester to check that I am targeting the correct CSS selectors. The record ids are correct when I check via the rails console.
I have put what I think are the important sections of code below, but I might be missing something that I don't realise is important.
The websites I'm having issues with are Lot-art.com & Lot-Tissimo.com
Any help will be much appreciated.
Seeded URLs
Source.create(name: "Auction.fr", query_template: "https://www.auction.fr/_en/lot/search/?contexte=futures&tri=date_debut%20ASC&query={query}&page={page}")
Source.create(name: "Invaluable.co.uk", query_template: "https://www.invaluable.co.uk/search/api/search-results?keyword={query}&size=1000")
Source.create(name: "Interencheres.com", query_template: "http://www.interencheres.com/en/recherche/lot?search%5Bkeyword%5D={query}&page={page}")
Source.create(name: "Gazette-drouot.com", query_template: "http://catalogue.gazette-drouot.com/html/g/recherche.jsp?numPage={page}&filterDate=1&query={query}&npp=100")
Source.create(name: "Lot-art.com", query_template: "http://www.lot-art.com/auction-search/?form_id=lot_search_form&page=1&mq=&q={query}&ord=recent")
Source.create(name: "Lot-tissimo.com", query_template: "https://lot-tissimo.com/en/cmd=s&lwr=&ww={query}&xw=&srt=SN&wg=EUR&page={page}")
Scheduler code
require 'rufus-scheduler'
require 'nokogiri'
require 'mechanize'
require 'open-uri'
require "net/https"
s = Rufus::Scheduler.singleton
s.interval '1m' do
setting = Setting.find(1)
agent = Mechanize.new
agent.user_agent_alias = 'Windows Chrome'
agent.cookie_jar.load(File.join(Rails.root, 'tmp/cookies.yaml'))
List.all.each do |list|
number_of_new_items = 0
list.actions.each do |action|
url = action.source.query_template.gsub('{query}', action.list.query)
case action.source.id
when 1 # Auction.fr
20.downto(1) do |page|
doc = Nokogiri::HTML(open(url.gsub('{page}', page.to_s)))
doc.css("div.list-products > ul > li").reverse.each do |item_data|
price = 0
if item_data.at_css("h3.h4.adjucation.ft-blue") && /Selling price : ([\d\s]+) €/.match(item_data.at_css("h3.h4.adjucation.ft-blue").text)
price = /Selling price : ([\d\s]+) €/.match(item_data.at_css("h3.h4.adjucation.ft-blue").text)[1].gsub(" ", "")
end
item = action.items.new(
title: item_data.at_css("h2").text.strip,
url: item_data.at_css("h2 a")["href"],
picture: item_data.at_css("div.image-wrap.lazy div.image img")["src"],
price: price,
currency: "€"
)
ActiveRecord::Base.logger.silence do # This disable writing logs
if item.save
number_of_new_items = number_of_new_items + 1
end
end
end
end
when 97 # Lot-Tissimo.com
5.downto(1) do |page|
doc = Nokogiri::HTML(open(url.gsub('{page}', page.to_s)))
doc.css("#inhalt > .objektliste").reverse.each do |item_data|
# price = 0
# if item_data.at_css("h3.h4.adjucation.ft-blue") && /Selling price : ([\d\s]+) €/.match(item_data.at_css("h3.h4.adjucation.ft-blue").text)
# price = /Selling price : ([\d\s]+) €/.match(item_data.at_css("h3.h4.adjucation.ft-blue").text)[1].gsub(" ", "")
# end
item = action.items.new(
title: item_data.at_css("div.objli-desc").text.strip,
url: item_data.at_css("td.objektliste-foto a")["href"],
picture: item_data.at_css("td.objektliste-foto a#lot_link img")["src"],
price: price,
currency: "€"
)
ActiveRecord::Base.logger.silence do # This disable writing logs
if item.save
number_of_new_items = number_of_new_items + 1
end
end
end
end
when 2 # Invaluable.co.uk
doc = JSON.parse(open(url).read)
doc["itemViewList"].reverse.each do |item_data|
puts item_data["itemView"]["photos"]
item = action.items.new(
title: item_data["itemView"]["title"],
url: "https://www.invaluable.co.uk/buy-now/" + item_data["itemView"]["title"].parameterize + "-" + item_data["itemView"]["ref"],
picture: item_data["itemView"]["photos"] != nil ? item_data["itemView"]["photos"].first["_links"]["medium"]["href"] : nil,
price: item_data["itemView"]["price"],
currency: item_data["itemView"]["currencySymbol"]
)
ActiveRecord::Base.logger.silence do # This disable writing logs
if item.save
number_of_new_items = number_of_new_items + 1
end
end
end
when 3 # Interencheres.com
# doc = Nokogiri::HTML(open(url))
5.downto(1) do |page|
doc = Nokogiri::HTML(open(url.gsub('{page}', page.to_s)))
doc.css("div#lots_0 div.ligne_vente").reverse.each do |item_data|
price = 0
item = action.items.new(
title: item_data.at_css("div.ph_vente div.des_vente p a").text.strip,
url: "http://www.interencheres.com" + item_data.at_css("div.ph_vente div.des_vente p a")["href"],
picture: item_data.at_css("div.ph_vente div.gd_ph_vente img")["src"],
price: price,
currency: "€"
)
ActiveRecord::Base.logger.silence do # This disable writing logs
if item.save
number_of_new_items = number_of_new_items + 1
end
end
end
end
when 4 # Gazette-drouot.com
5.downto(1) do |page|
# doc = Nokogiri::HTML(open(url.gsub('{page}', page.to_s)))
doc = agent.get(url.gsub('{page}', page.to_s))
# doc = agent.get(url)
doc.css("div#recherche_resultats div.lot_recherche").reverse.each do |item_data|
price = 0
picture = item_data.at_css("img.image_thumb_recherche") ? item_data.at_css("img.image_thumb_recherche")["src"] : nil
item = action.items.new(
title: item_data.at_css("#des_recherche").text.strip.truncate(140),
url: "http://catalogue.gazette-drouot.com/html/g/" + item_data.at_css("a.lien_under")["href"],
picture: picture,
price: price,
currency: "€"
)
ActiveRecord::Base.logger.silence do # This disable writing logs
if item.save
number_of_new_items = number_of_new_items + 1
end
end
end
end
when 69 # Lot-art.com
doc = agent.get(url)
doc.css("div.lot_list_holder").reverse.each do |item_data|
price = 0
item = action.items.new(
title: item_data.at_css("div.lot_list_body a")[0].text.strip.truncate(140),
url: item_data.at_css("div.lot_list_body")["href"],
picture: item_data.at_css("a.lot_list_thumb img") ["src"],
price: price,
currency: "€"
)
ActiveRecord::Base.logger.silence do # This disable writing logs
if item.save
number_of_new_items = number_of_new_items + 1
end
end
end
end
end
if number_of_new_items > 0 && setting.notifications_per_hour > setting.notifications_this_hour && setting.pushover_app_token.present? && setting.pushover_user_key.present?
url = URI.parse("https://api.pushover.net/1/messages.json")
req = Net::HTTP::Post.new(url.path)
req.set_form_data({
:token => setting.pushover_app_token,
:user => setting.pushover_user_key,
:message => "#{number_of_new_items} new items on #{list.name}!",
:url_title => "Check the list",
:url => "http://spottheauction.com/lists/#{list.id}"
})
res = Net::HTTP.new(url.host, url.port)
res.use_ssl = true
res.verify_mode = OpenSSL::SSL::VERIFY_PEER
res.start {|http| http.request(req) }
end
end
agent.cookie_jar.save(File.join(Rails.root, 'tmp/cookies.yaml'))
end
s.cron '0 * * * *' do
setting = Setting.find(1)
setting.notifications_this_hour = 0
setting.save
end
new just initializes an instance but doesn't save the instance. Do you actually call save somewhere?
You have two options:
Call save on the item:
item = action.items.new(
# ...
)
item.save
Or use create instead of new:
item = action.items.create(
# ...
)
In case someone else comes across this. I got the scraping of lot-art.com to work. It seemed that I was lacking specificity in the css selector for nokogiri to pull the correct data.
I am still having continuing issues with lot-tissimo although that appears to be from something else as other scrapers have issues such as scraping-hub's portia spiders.
I have the following code which takes a hash and turns all the values in to strings.
def stringify_values obj
#values ||= obj.clone
obj.each do |k, v|
if v.is_a?(Hash)
#values[k] = stringify_values(v)
else
#values[k] = v.to_s
end
end
return #values
end
So given the following hash:
{
post: {
id: 123,
text: 'foobar',
}
}
I get following YAML output
--- &1
:post: *1
:id: '123'
:text: 'foobar'
When I want this output
---
:post:
:id: '123'
:text: 'foobar'
It looks like the object has been flattened and then been given a reference to itself, which causes Stack level errors in my specs.
How do I get the desired output?
A simpler implementation of stringify_values can be - assuming that it is always a Hash. This function makes use of Hash#deep_merge method added by Active Support Core Extensions - we merge the hash with itself, so that in the block we get to inspect each value and call to_s on it.
def stringify_values obj
obj.deep_merge(obj) {|_,_,v| v.to_s}
end
Complete working sample:
require "yaml"
require "active_support/core_ext/hash"
def stringify_values obj
obj.deep_merge(obj) {|_,_,v| v.to_s}
end
class Foo
def to_s
"I am Foo"
end
end
h = {
post: {
id: 123,
arr: [1,2,3],
text: 'foobar',
obj: { me: Foo.new}
}
}
puts YAML.dump (stringify_values h)
#=>
---
:post:
:id: '123'
:arr: "[1, 2, 3]"
:text: foobar
:obj:
:me: I am Foo
Not sure what is the expectation when value is an array, as Array#to_s will give you array as a string as well, whether that is desirable or not, you can decide and tweak the solution a bit.
There are two issues. First: the #values after the first call would always contain an object which you cloned in the first call, so in the end you will always receive a cloned #values object, no matter what you do with the obj variable(it's because of ||= operator in your call). Second: if you remove it and will do #values = obj.clone - it would still return incorrect result(deepest hash), because you are overriding existing variable call after call.
require 'yaml'
def stringify_values(obj)
temp = {}
obj.each do |k, v|
if v.is_a?(Hash)
temp[k] = stringify_values(v)
else
temp[k] = v.to_s
end
end
temp
end
hash = {
post: {
id: 123,
text: 'foobar',
}
}
puts stringify_values(hash).to_yaml
#=>
---
:post:
:id: '123'
:text: foobar
If you want a simple solution without need of ActiveSupport, you can do this in one line using each_with_object:
obj.each_with_object({}) { |(k,v),m| m[k] = v.to_s }
If you want to modify obj in place pass obj as the argument to each_with_object; the above version returns a new object.
If you are as aware of converting values to strings, I would go with monkeypatching Hash class:
class Hash
def stringify_values
map { |k, v| [k, Hash === v ? v.stringify_values : v.to_s] }.to_h
end
end
Now you will be able to:
require 'yaml'
{
post: {
id: 123,
text: 'foobar'
},
arr: [1, 2, 3]
}.stringify_values.to_yaml
#⇒ ---
# :post:
# :id: '123'
# :text: foobar
# :arr: "[1, 2, 3]"
In fact, I wonder whether you really want to scramble Arrays?
Building a Rails 3.2 app with Ruby 1.9.
I am trying to write a helper method that initializes 3 variables and when i try to call the initialized variables from my view i get an "undefined method" error.
Method In Helper File
module StoreHelper
class Status
def initialize(product)
product_sales = product.line_items.total_product_sale.sum("quantity")
#avoid nil class errors for vol2 and 3. volume 1 can never be nil
if product.volume2.nil?
product.volume2 = 0
end
if product.volume3.nil?
product.volume3 = 0
end
#Promo status logic
if (product_sales >= product.volume2) && (product_sales < product.volume3)
#level3_status = "Active"
#level2_status = "On!"
#level1_status = "On!"
elsif (product_sales >= product.volume3)
#level3_status = "On!"
#level2_status = "On!"
#level1_status = "On!"
else #level3_status = "Pending"
end
end
I then attempt to call the the initialized variable #level3_status like so
<%=level3_status (product)%>
Not sure what i'm doing wrong any help would be appreciated.
How long are you programming with ruby? You have to create a new instance of your class to access the instance outside. Take a look at these basics: http://www.tutorialspoint.com/ruby/ruby_variables.htm
UPDATE
From the link above..
Ruby Instance Variables:
Instance variables begin with #. Uninitialized instance variables have the value nil and produce warnings with the -w option.
Here is an example showing usage of Instance Variables.
class Customer
def initialize(id, name, addr)
#cust_id=id
#cust_name=name
#cust_addr=addr
end
def display_details()
puts "Customer id ##cust_id"
puts "Customer name ##cust_name"
puts "Customer address ##cust_addr"
end
end
# Create Objects
cust1=Customer.new("1", "John", "Wisdom Apartments, Ludhiya")
cust2=Customer.new("2", "Poul", "New Empire road, Khandala")
# Call Methods
cust1.display_details()
cust2.display_details()
That´s how you can work with ruby and instance variables. More details are in the link.
In your case I think you have another "error", you mixed a few things.. where is your helper class? Under the app/helpers/store_helper.rb? In this file you should just add view helpers. If I am right with my intuitions I would solve your problem like following:
app/helpers/store_helper.rb
module StoreHelper
def get_level_states(product)
product_sales = product.line_items.total_product_sale.sum("quantity")
product.volume2 = 0 if product.volume2.nil?
product.volume3 = 0 if product.volume3.nil?
levels = {}
if (product_sales >= product.volume2) && (product_sales < product.volume3)
levels[:1] = "On!"
levels[:2] = "On!"
levels[:3] = "Active!"
elsif product_sales >= product.volume3
levels[:1] = "On!"
levels[:2] = "On!"
levels[:3] = "On!"
else
levels[:3] = "Pending"
end
levels
end
end
app/views/your_views_folder/your_view.html.erb
to get the different level state:
<% levels = get_level_states(product) %>
<%= levels[:1] %> # will print the level 1
<%= levels[:2] %> # will print the level 2
<%= levels[:3] %> # will print the level 3
I'm writing a web based Ruby program using the IDE RubyMine.
I have a couple of classses:
application_controller.rb:
class application_controller < ActionController::Base
# To change this template use File | Settings | File Templates.
# require './course_modules.rb'
def initialize
self.class.main_menu
end
=begin
def navigateTo(what)
what.new(v).display
mainMenu
end
=end
def self.main_menu
puts "What would you like to do?
1: Add module to a scheme
2: Remove module from a scheme
3: Query modules
4: Modify module
5: Register a student on a scheme
6: Remove a student from a scheme
7: Register a student on a module
8: Remove a student from a module"
case gets.strip
when "1"
CourseModules.add_module
when "2"
CourseModules.remove_module
when "3"
navigateTo CourseModules
when "4"
navigateTo CourseModules
when "5"
navigateTo Student
when "6"
navigateTo Student
when "7"
navigateTo Student
end
end
Application.new
end
and course_modules.rb:
class CourseModulesController < ActionController::Base
# To change this template use File | Settings | File Templates.
##moduleScheme = nil
##moduleYear = nil
##moduleTitle = ""
#noOfModulesInScheme = 0
$schemes = {}
$module_ID = 0
$module_exists = false
def self.moduleYear
##moduleYear
end
def initialize(v)
#val = v
end
# Set and get the #val object value
def set (v)
#val = v
end
def get
return #val
end
# Attempt at add_module method on 21/08/2012 at 16:30
def self.add_module
# schemes = {}
scheme_exists = false
add_another_scheme = true
# module_exists = false
add_another_module = true
while add_another_scheme
print "Enter scheme name: "
scheme_name = gets
$schemes.has_key?(scheme_name.chop) ? scheme_exists = true : scheme_exists = false
if !scheme_exists
$schemes[scheme_name.chop] = []
puts "Scheme #{scheme_name.chop} has been added to the system"
elsif
scheme_exists == true
puts "This scheme has already been added"
end
while add_another_module
print "Enter module name: "
module_name = gets
$schemes[scheme_name.chop].include?(module_name.chop) ? true : $schemes[scheme_name.chop] << module_name.chop
# puts "Module #{module_name.chop} has been added to #{scheme_name.chop}"
# 22/08/2012 at 14:15 Now need to read in each module's unique identifier and year it belongs to
print "Enter module ID: "
$module_ID =gets
$schemes[scheme_name.chop].include?($module_ID.chop) ? true : $schemes[scheme_name.chop] << $module_ID.chop
$schemes.has_key?($module_ID.chop) ? module_exists = true : module_exists = false
print "Enter the academic year to which the module belongs: "
module_year = gets
$schemes[scheme_name.chop].include?(module_year.chop) ? true : $schemes[scheme_name.chop] << module_year.chop
if !$module_exists
$schemes[$module_ID.chop] = []
puts "Module #{$module_ID.chop} : #{module_name.chop} has been added to #{scheme_name.chop} for the year #{module_year}"
elsif
$module_exists == true
puts "A module with this ID has already been added to the scheme, please check if the module already exists, or choose another ID "
else
# puts "Module #{module_name.chop}, #{module_ID.chop} has been added to #{scheme_name.chop} for the year #{module_year}"
end
# puts "Module #{module_name.chop}, #{module_ID.chop} has been added to #{scheme_name.chop}"
print "Add another module? "
ask_if_user_wants_to_add_another_module = gets
if(ask_if_user_wants_to_add_another_module.chop == "y" or ask_if_user_wants_to_add_another_module == "yes")
add_another_scheme = false
else if(ask_if_user_wants_to_add_another_module.chop != "y" or ask_if_user_wants_to_add_another_module != "yes")
Application.main_menu
end
end
end
print "Add another scheme? "
ask_if_user_wants_to_add_another_scheme = gets
if !(ask_if_user_wants_to_add_another_scheme.chop == "y" or ask_if_user_wants_to_add_another_scheme.chop == "yes")
add_another_scheme = false
end
puts $schemes
end
while add_another_module
print "Enter scheme name: "
scheme_name = gets
#$schemes.has_key?(scheme_name.chop) ? scheme_exists = true : scheme_exists = false
scheme_exists = $schemes.has_key? (scheme_name.chop)
if !scheme_exists
print "Enter module name: "
module_name = gets
$schemes[scheme_name.chop] = module_name.chop
puts "Scheme #{scheme_name.chop} with module #{module_name} has been added to the system"
else
scheme_exists = false
puts "This scheme has already been added"
puts "Enter module name: "
module_name = gets
$schemes[scheme_name.chop] = module_name.chop
puts "Scheme #{scheme_name.chop} with module #{module_name} has been added to the system"
end
print "Add another module? "
ask_if_user_wants_to_add_another_module = gets
if !(ask_if_user_wants_to_add_another_module.chop == "y" or ask_if_user_wants_to_add_another_module.chop == "yes")
add_another_module = false
end
end
puts $schemes
end
def self.remove_module
print "Which scheme would you like to remove a module from? "
scheme_name = gets
#$schemes.has_key?(scheme_name.chop) ? scheme_exists = true : scheme_exists = false
scheme_exists = $schemes.has_key? (scheme_name.chop)
if !scheme_exists
$schemes[scheme_name.chop] = []
puts "Scheme #{scheme_name.chop} doesn't exist"
else
scheme_exists = true
puts "Which module would you like to remove from #{scheme_name.chop}?"
$module_ID = gets
if !$module_exists
$schemes[$module_ID.chop] = []
puts "Module #{$module_ID.chop} : does not exist in #{scheme_name.chop} "
else
module_exists = true
puts "Module #{$module_ID.chop} has been removed from #{scheme_name.chop} "
# puts "Module #{module_name.chop}, #{module_ID.chop} has been added to #{scheme_name.chop} for the year #{module_year}"
end
end
end
end
When I browse to
http://localhost:3000
in Firefox, to view my web page, I'm getting a web page that's displaying an error message:
The error message says:
SyntaxError in ApplicationController#main_menu
(Filepath)/application_controller.rb:1: class/module name must be CONSTANT
class application_controller < ActionController::Base
Rails.root: (Filepath)/CourseManagementSystem
Does anyone know why I'm not getting a web page displaying my web application? How can I put this right?
class application_controller < ActionController::Base
This should be
class ApplicationController < ActionController::Base
application_controller is an invalid class name in ruby. You can test this simply in IRB by running
➜ ~ irb
irb(main):001:0> class a;end
SyntaxError: (irb):1: class/module name must be CONSTANT
class a;end
^
from /Users/deefour/.rbenv/versions/1.9.3-p125/bin/irb:12:in `<main>'
With a properly named class (A instead of a), there is no such issue
➜ ~ irb
irb(main):001:0> class A;end
=> nil
irb(main):002:0>