Thanks for all of the help! Like I said, I'm new with Ruby on Rails
and many of the basics that I learned in tutorials were mostly Ruby
code. I thought there was probably a good way to do this in the
controller.

So I've updated my controller to read:

def index
    @events = current_user.events.find(:all, :order => "date")
end

Works perfectly with the scaffolding that's in place.

Thanks for the tip on the using "Date" as a model name. Luckily, I
didn't do that and only used it in my previous example.

On Mar 10, 2:20 pm, Robert Walker <[email protected]> wrote:
> Dubocit wrote:
> > I'm a newbie and was curious about displaying scaffold views ascending
> > or descending by date. Here's what my current view looks like. The
> > first column is the one I'd like to sort by so that the user can see
> > each date in order as the event date is approaching. My controller is
> > just the generated scaffold controller. I know that the default for
> > Rails is to display each record by when it was created.
>
> This isn't true. Rails has no default for sorting result sets. Rails
> just includes them in the order the query provides them.
>
> > How can I go about displaying this table by dates and what's the best way 
> > to do it?
>
> Ask the database to put them in the order you want inside your
> controller action. It's should the controller's responsibility to fetch
> and organize the data to be presented not the view's.
>
> def index
>   @dates = DateModel.find(:all, :order => "date")
> end
>
> P.S. I hope did didn't name your ActiveRecord model "Date" that might
> cause you problems in the future.
>
> P.P.S. I'd also recommend not naming a database column "date" either.
> You may run into naming conflicts and other issues as well. Rails has a
> convention for naming date and time related fields (i.e. created_at,
> updated_on). I'd recommend following that convention for your own date
> fields. Use *_on for date fields and *_at for datetime fields in order
> to avoid any possible naming conflicts.
> --
> Posted viahttp://www.ruby-forum.com/.

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to