Dave Castellano

Joined

130 Experience
0 Lessons Completed
0 Questions Solved

Activity

Hi all! Hope you dont mind a newbie question...

I need to categorize questions to several levels:
Subject
Book
Chapter
Section
Subsection
Minisection
Question
So Subject has many Books , Books has many Chapters... down to Minisection has many Questions .
I assume its like the more common Country -State-City- County- ect..
Is there a preferred way to set up tables and associations in this scenario?
Can I use the has_many :through association to link all the tables, with more than 3 tables involved?

Thanks!

Posted in Model/concerns question

<%= @subject.title %>

Posted in Model/concerns question

Thank you Chris. A screencast would be great!

There are no longer any error messages but the associated index.html.erb view outputs uncapitalized. When i put "debugger" inside:

class Subject < ActiveRecord::Base
include CapitalizeIt
def name
debugger
capitalize_title(self.title)
end
end

It is not seen and debugger is not activated

Posted in Model/concerns question

Not solved!

Posted in Model/concerns question

Hi. I am learning ROR on my own (no formal programming trainng) so this may be a question with an obvious answer but i'm stuck and the answer will help me understand how to call concerns. I have a method I want to use in several models - capitalize_it.
In app/models/concerns/capitalize_it:
module CapitalizeIt
extend ActiveSupport::Concern

module ClassMethods
def capitalize_title(title) # Capitalizes multi-word titles.
cap_stop_words = %w(for and the of to at is a)
title.capitalize!
n = 0
title = title.split(" ").collect{ |word|
if n == 0
n=n+1
word.capitalize
else
cap_stop_words.include?(word) ? word : word.capitalize
end
}.join(" ")
end
end
end

In model: Have tried several ways to pass the title arguement to the module... to no avail!
class Subject < ActiveRecord::Base
include CapitalizeIt
def name
self.title
end
capitalize_title(name)

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

© 2024 GoRails, LLC. All rights reserved.