On Aug 29, 2012, at 3:56 PM, Colin Law wrote:
> On 29 August 2012 18:44, Walter Lee Davis <waltd@wdstudio.com> wrote:
>>
>> On Aug 29, 2012, at 12:04 PM, Colin Law wrote:
>>
>>> On 29 August 2012 16:13, Walter Lee Davis <waltd@wdstudio.com> wrote:
>>>> I have a model that includes a :current boolean. The idea is that there are many home pages that the admin is working on at any given time, but only one is current at a time. At the moment, I have enforced this with the following:
>>>
>>> I think you may have this the wrong way round, instead of remembering
>>> which one is current in the page put it in the admin model, then you
>>> only need to change it there and not touch the pages at all.
>>
>> Admin is a subset of User, I was referring to him or her as a person, not a model. I am not sure why that model would be the place, though. I want to route /home to homes#default, where homes_controller#default looks like this:
>
> Database design is nothing to do with routing. Get the database
> design right and separately sort out what views you want and hence the
> controllers and routing. You said that an admin (that is a User) at
> any time has one current home page. You have gone for the solution of
> remembering in the page record that it is, or is not, current, which
> involves the problems you have found with making sure that only one is
> current at any one time. Also there is redundant information in the
> db, the fact that one of the records has its current flag set implies
> that all the others are clear. In addition it is possible to have an
> illegal condition in the database where more than one is marked as
> current, these both suggest that there may be a better way of
> organising the data. An alternative solution is to remember in the
> User record which page is his current home page, which appears to me
> be an easier solution and is much less prone to subtle programming
> errors.
Oh, I see what you were thinking. This is not the Admin's (personal) home page, it is the one and only home page for the entire public site. The admin is responsible for assembling this home page by choosing items to featured on it, but the home page that results (one of many that the admin may be working on for future use) is going to be shown to the world one at a time, by means of the current flag.
Does that change your mind about what I might want to do here?
Walter
>
> Colin
>
>
>>
>> def default
>> @home = Home.default
>> render :action => 'show'
>> end
>>
>> and home#default looks like this:
>>
>> def self.default
>> @default ||= Home.where(:current => true).first || Home.order('added_at DESC').first || Home.new
>> end
>>
>> This is all working, I was just looking for a way to make it more canonical.
>>
>> Walter
>>
>>>
>>> Colin
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
>>> To post to this group, send email to rubyonrails-talk@googlegroups.com.
>>> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
>> To post to this group, send email to rubyonrails-talk@googlegroups.com.
>> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment