(Preface: I am 10 months into learning Rails so this could be a really rookie mistake.)
My app has Venues which have VenueCategories associated with them. In my Venue view, I want to populate some hash tags into the share content when a user shares the Venue to Twitter. For this, I have created a method (albeit perhaps not an ideal implementation, will look to refactor later) hash_tags to be called on the VenueCategory. First I put this in VenueCategoriesHelper.rb and got NoMethodError when calling it in the console to test. I moved the method to both the Model and the Controller just to test it out but yielded the same results.
I have tried defining the method with and without passing the venue_category as a parameter.
What am I doing wrong? Relevant code below.
VenueCategoriesHelper.rb
def hash_tags(venue_category)
hash_tags = []
hash_tag_string = ""
if venue_category.name == "Restaurant"
hash_tags << "#restaurants"
elsif venue_category.name == "Salons & Spas"
hash_tags << ["#salons", "#spas"]
elsif venue_category.name == "Hotels & Resorts"
hash_tags << ["#hotels", "#resorts"]
elsif venue_category.name == "Bars & Nightlife"
hash_tags << ["#bars", "#nightlife"]
end
hash_tags.each do |h|
hash_tag_string << "#{h} "
end
end
show.html.slim (random snippet added to view to test
...
p = resource.venue_category.hash_tags(resource.venue_category)
#header-module
#overall-score-container
#overall-score-header
...
Error from Console and when running in browser
NoMethodError: undefined method `hash_tags' for #<VenueCategory:0x007ff2134b69c0>
Thanks in advance for any and all help!
reload!in the console.VenueCategory.new.hash_tags(:foo)? If so, does the error persist, when you exit the console and restart it?