The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

HolyMoly (14) [Avatar] Offline
#1
There's some difficult code (for me) that's not explained in the book

a) What is the purpose of self.default = true in the code below

b) is the 'default' in that line the same default that comes from the dynamic finder?

c) what exactly is being saved when you write "self.save!"

def default!
current_default_state = State.find_by_default(true)

self.default = true
self.save!
if current_default_state current_default_state.default = false current_default_state.save!

end
end
RubyHo (9) [Avatar] Offline
#2
Re: What is the purpose of self.default = true
I find this is one of the things I don't like about the book. It over-explains a lot of easy code but then it doesn't explain the trickier parts.
ryanbigg (423) [Avatar] Offline
#3
Re: What is the purpose of self.default = true
Hi,

The code there is setting the default attribute on the record to be true, making the current state the now default state. If there is already a state that *was* previously the default, it makes that state's "default" attribute false, meaning there will only be one default state.
ryanbigg (423) [Avatar] Offline
#4
Re: What is the purpose of self.default = true
RubyHo,

If you could point out those areas that you think we need improvement around I'd be more than happy to fix them up.

Thanks!
RubyHo (9) [Avatar] Offline
#5
Re: What is the purpose of self.default = true
O.K, Ryan, I will do that.

I think it's a really good book too, but there is room for improvement (I believe). Since beginners are part of your target audience, I think you need to cover all the bases for their level but sometimes you rush over things. Maybe things that are clear to you aren't always clear to others.

But still I am very impressed and hope you will continue writing.