Anyone? Any help would be much appriciated,
Thanks In Advance, Joe On May 3, 11:28 am, Joe <j...@dev-hq.co.uk> wrote: > So I change it to this: <%= render :partial => > @category.tutorials.ordered_by_position %> > and I get the error: undefined method `ordered_by_position' > > I'm guessing that's because I have to create a method that orders them > by position. However I'm a noob in ruby on rails, where do I create > the method, and how do I make it order them by position? > > Thanks in advance, > > Sorry for being such a noob, > > Joe > > On May 3, 10:35 am, Frederick Cheung <frederick.che...@gmail.com> > wrote: > > > > > On May 3, 8:12 am, Joe <j...@dev-hq.co.uk> wrote: > > > > Ok, so I've created my position thing for every tutorial. However now > > > I need to know how I can setup render :partial to order the tutorials > > > using the position, and then if two (or more) tutorials have the same > > > position, then go back and check there id, and order the ones with the > > > same position by id. > > > > This is how I'm currently displaying the tutorials: > > > > <%= render :partial => @category.tutorials %> > > > > Does anyone have any ideas how I can adapt this? > > > I'd probably create a named_scope on Tutorial which ordered things by > > position. Since named_scopes can be chained with each other and with > > an association you could do @category.tutorials.ordered_by_position > > > Fred > > > > Thanks In Advance, > > > > Joe > > > > On May 2, 9:18 pm, Joe <j...@dev-hq.co.uk> wrote: > > > > > Ok, So it seems that this whole tutorial ordering thing seems to be > > > > the best way to go (thanks to philip anyway for giving me the code to > > > > do it with ids if I wanted to); > > > > The problem is I'm really a complete noob in RoR. I know how to create > > > > migrations, however creating a "position" variable i which they were > > > > independent to the category the tutorials were in; I have absolutely > > > > no idea how to do that. And you talk about writing methods, I also do > > > > not know where these methods would be created (inside a controller > > > > perhaps?). > > > > > Any help with this task would be kindly appriciated, > > > > > Thanks In Advance, > > > > > Joe > > > > > On May 2, 7:18 pm, Philip Hallstrom <phi...@pjkh.com> wrote: > > > > > > >> The tutorials are then displayed in order of there id (auto- > > > > > >> incrementing) in their categories show method. > > > > > >> The thing is, I want to create a link that goes from one tutorial > > > > > >> (with an id of 10 for example) to the next tutorial in that > > > > > >> category > > > > > >> (which might not have an id of 11, as I create different tutorials > > > > > >> at > > > > > >> different times, therefore creating different ids for two tutorials > > > > > >> seemingly next to eachother in order). > > > > > > >> Obviously I know I will need something like this: > > > > > >> <%= link_to 'Next lesson....', %> > > > > > > >> but I just don't know how I can manage it.. > > > > > > >> By the way, every tutorial has a: category_id to determain which > > > > > >> category they are in (this is an integer). > > > > > > > If I were you, i'd create a position column on tutorials, which > > > > > > determines the ordering of tutorials for a category (ordering by id > > > > > > might seem the simplest but stops you from ever reordering > > > > > > tutorials. > > > > > > Given a tutorial, the next one is the first one in the same category > > > > > > whose position is greater than the current ones (you could write a > > > > > > next_tutorial method on tutorial). There's a plugin called > > > > > > acts_as_list that you might find helpful maintaining the position > > > > > > column. If you're hell bent on ordering by id then it's as if id is > > > > > > your position column > > > > > > > Fred > > > > > > I agree with Fred as it allows you to easily re-order the tutorials > > > > > if > > > > > you want to, but if you don't... then... > > > > > > next_tutorial = Tutorial.find(:conditions => ["id > ? AND category_id > > > > > > > > > > = ?", current_tutorial_id, current_category_id], :order => > > > > > 'id', :limit => 1) > > > > > > prev_tutorial = Tutorial.find(:conditions => ["id < ? AND category_id > > > > > > > > > > = ?", current_tutorial_id, current_category_id], :order => 'id > > > > > DESC', :limit => 1) > > > > > > -- > > > > > 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-t...@googlegroups.com. > > > > > To unsubscribe from this group, send email to > > > > > rubyonrails-talk+unsubscr...@googlegroups.com. > > > > > For more options, visit this group > > > > > athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > -- > > > > 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-t...@googlegroups.com. > > > > To unsubscribe from this group, send email to > > > > rubyonrails-talk+unsubscr...@googlegroups.com. > > > > For more options, visit this group > > > > athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > > > -- > > > 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-t...@googlegroups.com. > > > To unsubscribe from this group, send email to > > > rubyonrails-talk+unsubscr...@googlegroups.com. > > > For more options, visit this group > > > athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > 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-t...@googlegroups.com. > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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-t...@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/rubyonrails-talk?hl=en. -- 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-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.