Hi, Basically I currently have this system where there are categories, and tutorials; obviously categories have many tutorials, and every tutorial must belong_to a category. 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). Please Help, Thanks In Advance, Joe -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On May 2, 1:29 pm, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> 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 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Philip Hallstrom
2010-May-02 18:18 UTC
Re: Re: Finding the next item, in a group of items.
>> 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 > > FredI 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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...-LSG90OXdqQE@public.gmane.org> 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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? Thanks In Advance, Joe On May 2, 9:18 pm, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> 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...-LSG90OXdqQE@public.gmane.org> 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On May 3, 8:12 am, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> 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...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> 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...-LSG90OXdqQE@public.gmane.org> 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-talk-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On May 3, 8:12 am, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> 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...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> 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...-LSG90OXdqQE@public.gmane.org> 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-talk@googlegroups.com. > > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > 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-talk-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
youtube-T/oTI28FLjDQXOPxS62xeg@public.gmane.org
2010-May-05 14:51 UTC
Re: Finding the next item, in a group of items.
Anyone? Any help would be much appriciated, Thanks In Advance, Joe On May 3, 11:28 am, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> 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...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > On May 3, 8:12 am, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> 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...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> 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...-LSG90OXdqQE@public.gmane.org> 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-talk@googlegroups.com. > > > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > > 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-talk@googlegroups.com. > > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > 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-talk-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
youtube-T/oTI28FLjDQXOPxS62xeg@public.gmane.org
2010-May-05 15:03 UTC
Re: Finding the next item, in a group of items.
Anyone? Any help would be much appriciated, Thanks In Advance, Joe On May 3, 11:28 am, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> 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...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > On May 3, 8:12 am, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> 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...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> 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...-LSG90OXdqQE@public.gmane.org> 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-talk@googlegroups.com. > > > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > > 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-talk@googlegroups.com. > > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > 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-talk-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
youtube-T/oTI28FLjDQXOPxS62xeg@public.gmane.org
2010-May-05 15:04 UTC
Re: Finding the next item, in a group of items.
Anyone? Any help would be much appriciated, Thanks In Advance, Joe On May 3, 11:28 am, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> 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...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > On May 3, 8:12 am, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> 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...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> 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...-LSG90OXdqQE@public.gmane.org> 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-talk@googlegroups.com. > > > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > > 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-talk@googlegroups.com. > > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > 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-talk-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Just to confirm the above IS me asking for more help; and I didn''t mean to post 3 times, I think it glitched a bit. Please Help, Thanks In Advance, Joe On May 5, 4:04 pm, yout...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org wrote:> Anyone? > > Any help would be much appriciated, > > Thanks In Advance, > > Joe > > On May 3, 11:28 am, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> 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...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > On May 3, 8:12 am, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> 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...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> 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...-LSG90OXdqQE@public.gmane.org> 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-talk@googlegroups.com. > > > > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > > > 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-talk@googlegroups.com. > > > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > > 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-talk@googlegroups.com. > > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > 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-talk-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On May 3, 11:28 am, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> 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? >Well a trick here is that if you make a class method on Tutorial then you can call it on a tutorials association and will work just fine, and any finds and so on are scoped to the association. So you could write class Tutorial < AR::Base def self.ordered_by_position find :all, :order => ''position'' end end A better choice for this sort of thing is named_scope. They are more flexible and more reusable. Have a look at the docs for those. Fred> Thanks in advance, > > Sorry for being such a noob, > > Joe > > On May 3, 10:35 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > > > On May 3, 8:12 am, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> 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...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> 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...-LSG90OXdqQE@public.gmane.org> 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-talk@googlegroups.com. > > > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > > 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-talk@googlegroups.com. > > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > 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-talk-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks for your help, but I''m not sure where classes go. I''ve tried copying this code into the tutorials_controller: def self.ordered_by_position find :all, :order => ''position'' end But it still has this error: undefined method `ordered_by_position'' I assume this is because I have either put this code in the wrong place; of need to put it in a different place WITH this bit: class Tutorial < AR::Base (and of course the extra end).. I''m really sorry for being such a pain, Thanks In Advance, Joe -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 6 May 2010 15:46, Joe <joe-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote:> I''ve tried copying this code into the tutorials_controller: > > def self.ordered_by_position > find :all, :order => ''position'' > endIf you''re calling "Tutorial.ordered_by_position" that code needs to be in the Tutorial model, not in a controller... -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks so much! It works! However now I''m just trying to get the whole ''next lesson'' thing working. I''ve tried it using this code in the model: def self.next_lesson find :all, :conditions => ["position > ? AND category_id = ?", @tutorial_id, @category_id], :order => ''position'', :limit => 1 end and then this code in the link: <%= link_to ''Next lesson.'', @tutorial.next_lesson %> However I get this error: undefined method `next_lesson'' Why is this happening? and how do I overcome it? Thanks for your help, Joe On May 6, 3:48 pm, Michael Pavling <pavl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 6 May 2010 15:46, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote: > > > I''ve tried copying this code into the tutorials_controller: > > > def self.ordered_by_position > > find :all, :order => ''position'' > > end > > If you''re calling "Tutorial.ordered_by_position" that code needs to be > in the Tutorial model, not in a controller... > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 6 May 2010 16:41, Joe <joe-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote:> def self.next_lesson > find :all, :conditions => ["position > ? AND category_id = ?", > @tutorial_id, @category_id], :order => ''position'', :limit => 1 > end > > and then this code in the link: > > <%= link_to ''Next lesson.'', @tutorial.next_lesson %>using "self" in the method name makes it a class method; so accessible with "Tutorial.next_lesson". But you''d have to pass in the tutorial_id and category_id. Seriously - someone much earlier suggested using acts_as_list. Do. It deals with all of this for you... -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
When I change it to "Tutorial.next_lesson" it then says: undefined method `nil_class_path'' Is this because I have to "pass in the tutorial_id and category_id" or is it a different problem? As for acts_as_list, I would prefer not to use it for now and just keep with using position; However it is something I will be looking at for future projects.. Please Help, Sorry for being such a pain, Thanks In Advance, Joe On May 6, 4:48 pm, Michael Pavling <pavl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 6 May 2010 16:41, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote: > > > def self.next_lesson > > find :all, :conditions => ["position > ? AND category_id = ?", > > @tutorial_id, @category_id], :order => ''position'', :limit => 1 > > end > > > and then this code in the link: > > > <%= link_to ''Next lesson.'', @tutorial.next_lesson %> > > using "self" in the method name makes it a class method; so accessible > with "Tutorial.next_lesson". But you''d have to pass in the tutorial_id > and category_id. > > Seriously - someone much earlier suggested using acts_as_list. Do. It > deals with all of this for you... > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On May 6, 5:23 pm, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote:> When I change it to "Tutorial.next_lesson" it then says: undefined > method `nil_class_path'' > > Is this because I have to "pass in the tutorial_id and category_id" or > is it a different problem? >You''re probably getting nil_class_path because you are returning nil from somewhere. You definitely need to pass in the values of tutorial_id - that class method isn''t going to be stealing instance variables out of the controller or anything like that. Personally I''d have next_lesson be an instance method of tutorial link_to ''Next'', @tutorial.next_lesson sounds nicer than link_to ''Next'', Tutorial.next_lesson(@tutorial.id, @tutorial.category_id) or anything like that. Fred -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 6 May 2010 17:23, Joe <joe-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote:> As for acts_as_list, I would prefer not to use it for now and just > keep with using position; However it is something I will be looking at > for future projects..Why?! acts_as_list uses the position column itself. You can scope it (so you can have a list per category, or whatever) and it gives you the next/previous item methods: http://api.rubyonrails.org/classes/ActiveRecord/Acts/List/InstanceMethods.html As it is, you''re trying to reinvent the wheel. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I did try using: "@tutorial.next_lesson" before, however I got this error so figured it must be wrong: undefined method `next_lesson'' I don''t quite know why it can''t find the method since it''s obviously in the model... Has anyone got a solution for this? Thanks In Advance, Joe On May 6, 5:30 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On May 6, 5:23 pm, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote:> When I change it to "Tutorial.next_lesson" it then says: undefined > > method `nil_class_path'' > > > Is this because I have to "pass in the tutorial_id and category_id" or > > is it a different problem? > > You''re probably getting nil_class_path because you are returning nil > from somewhere. > You definitely need to pass in the values of tutorial_id - that class > method isn''t going to be stealing instance variables out of the > controller or anything like that. > Personally I''d have next_lesson be an instance method of tutorial > > link_to ''Next'', @tutorial.next_lesson > > sounds nicer than > > link_to ''Next'', Tutorial.next_lesson(@tutorial.id, > @tutorial.category_id) > > or anything like that. > > Fred > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Please note I''ve also tried this: Tutorial.next_lesson(@tutorial.id, @tutorial.category_id) Which results in some compile errors: wrong number of arguments (2 for 0) I guess this is because my model doesn''t take any parameters, and I''m giving it 2... I''ll be looking around for how I can make it accept 2 parameters (or fix the previous error) but it would be nice if someone could help out, Thanks In Advance, Joe On May 6, 8:00 pm, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote:> I did try using: "@tutorial.next_lesson" before, however I got this > error so figured it must be wrong: undefined method `next_lesson'' > > I don''t quite know why it can''t find the method since it''s obviously > in the model... > > Has anyone got a solution for this? > > Thanks In Advance, > > Joe > > On May 6, 5:30 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > On May 6, 5:23 pm, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote:> When I change it to "Tutorial.next_lesson" it then says: undefined > > > method `nil_class_path'' > > > > Is this because I have to "pass in the tutorial_id and category_id" or > > > is it a different problem? > > > You''re probably getting nil_class_path because you are returning nil > > from somewhere. > > You definitely need to pass in the values of tutorial_id - that class > > method isn''t going to be stealing instance variables out of the > > controller or anything like that. > > Personally I''d have next_lesson be an instance method of tutorial > > > link_to ''Next'', @tutorial.next_lesson > > > sounds nicer than > > > link_to ''Next'', Tutorial.next_lesson(@tutorial.id, > > @tutorial.category_id) > > > or anything like that. > > > Fred > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Would I be correct in saying it''s because the model method doesn''t expect to be given any parameters, or is it a different problem? It would seem that other people with errors of this kind are having different problems. Please Help, Thanks In Advance, Joe On May 7, 7:20 am, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote:> Please note I''ve also tried this: Tutorial.next_lesson(@tutorial.id, > @tutorial.category_id) > > Which results in some compile errors: wrong number of arguments (2 for > 0) > > I guess this is because my model doesn''t take any parameters, and I''m > giving it 2... > > I''ll be looking around for how I can make it accept 2 parameters (or > fix the previous error) but it would be nice if someone could help > out, > > Thanks In Advance, > > Joe > > On May 6, 8:00 pm, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote: > > > > > I did try using: "@tutorial.next_lesson" before, however I got this > > error so figured it must be wrong: undefined method `next_lesson'' > > > I don''t quite know why it can''t find the method since it''s obviously > > in the model... > > > Has anyone got a solution for this? > > > Thanks In Advance, > > > Joe > > > On May 6, 5:30 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > On May 6, 5:23 pm, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote:> When I change it to "Tutorial.next_lesson" it then says: undefined > > > > method `nil_class_path'' > > > > > Is this because I have to "pass in the tutorial_id and category_id" or > > > > is it a different problem? > > > > You''re probably getting nil_class_path because you are returning nil > > > from somewhere. > > > You definitely need to pass in the values of tutorial_id - that class > > > method isn''t going to be stealing instance variables out of the > > > controller or anything like that. > > > Personally I''d have next_lesson be an instance method of tutorial > > > > link_to ''Next'', @tutorial.next_lesson > > > > sounds nicer than > > > > link_to ''Next'', Tutorial.next_lesson(@tutorial.id, > > > @tutorial.category_id) > > > > or anything like that. > > > > Fred > > > > -- > > > 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-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Joe wrote:> Please note I''ve also tried this: Tutorial.next_lesson(@tutorial.id, > @tutorial.category_id) > > Which results in some compile errors: wrong number of arguments (2 for > 0) > > I guess this is because my model doesn''t take any parameters, and I''m > giving it 2... > > I''ll be looking around for how I can make it accept 2 parameters (or > fix the previous error) but it would be nice if someone could help > out,Check your method definition. It probably doesn''t expect 2 parameters. If you''re asking this sort of question, you really need to read Programming Ruby (available free at http://www.ruby-doc.org ). You can''t do Rails development without an understanding of the Ruby language, and you''ll get that understanding much faster by reading than by posting here.> > Thanks In Advance, > > JoeBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ah wow! That was pretty easy, just parameters like normal functions in other languages. Well I''ve got it to accept the parameters like this: def self.next_lesson(tutID, catID) find :all, :conditions => ["position > ? AND category_id = ?", tutID, catID], :order => ''position'', :limit => 1 end However I''m getting this error: undefined method `nil_class_path'' The show code is this: <%= link_to ''Next'', Tutorial.next_lesson(@tutorial.id, @tutorial.category_id) %> As far as I''m aware this is something to do with the link itself, but I don''t know why. Googling it seems to reveal it''s a common problem with many different solutions for different cases. Does anyone know why this is happening? EXTRA NOTE: By the way I plan to learn more ruby as it is really easy, and is helping my RoR lots. Please Help, Thanks In Advance, Joe Marnen Laibow-Koser wrote:> Joe wrote: > > Please note I''ve also tried this: Tutorial.next_lesson(@tutorial.id, > > @tutorial.category_id) > > > > Which results in some compile errors: wrong number of arguments (2 for > > 0) > > > > I guess this is because my model doesn''t take any parameters, and I''m > > giving it 2... > > > > I''ll be looking around for how I can make it accept 2 parameters (or > > fix the previous error) but it would be nice if someone could help > > out, > > Check your method definition. It probably doesn''t expect 2 parameters. > > If you''re asking this sort of question, you really need to read > Programming Ruby (available free at http://www.ruby-doc.org ). You > can''t do Rails development without an understanding of the Ruby > language, and you''ll get that understanding much faster by reading than > by posting here. > > > > > Thanks In Advance, > > > > Joe > > Best, > -- > Marnen Laibow-Koser > http://www.marnen.org > marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > -- > Posted via http://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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 7 May 2010 16:28, Joe <joe-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote:> <%= link_to ''Next'', Tutorial.next_lesson(@tutorial.id, > @tutorial.category_id) %> > > Does anyone know why this is happening?I''m only gonna reply this time because you''re being so dammed polite. But no more from me on this thread... You''re putting the result of your class method into the link_to; the link_to expects a single AR object, but the method is returning an array of them. You could test all this yourself in a console. Run your method and see what happens. Then either change the :all to :first, or do something else to get a single object (urm... I dunno... like maybe use a plugin that does it all for you... I''ve heard acts_as_list is good ;-)> EXTRA NOTE: By the way I plan to learn more ruby as it is really easy, > and is helping my RoR lots.Good for you. It will, given what the first ''R'' stands for! -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
THANK YOU! This was the missing piece of the puzzle, with changing it to :first and some more editing I''ve now got it to work! If I have any more problems I''ll probably create a new topic (unless I get them very quickly), Thanks again, Joe On May 7, 7:15 pm, Michael Pavling <pavl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 7 May 2010 16:28, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote: > > > <%= link_to ''Next'', Tutorial.next_lesson(@tutorial.id, > > @tutorial.category_id) %> > > > Does anyone know why this is happening? > > I''m only gonna reply this time because you''re being so dammed polite. > But no more from me on this thread... > > You''re putting the result of your class method into the link_to; the > link_to expects a single AR object, but the method is returning an > array of them. > > You could test all this yourself in a console. Run your method and see > what happens. Then either change the :all to :first, or do something > else to get a single object (urm... I dunno... like maybe use a plugin > that does it all for you... I''ve heard acts_as_list is good ;-) > > > EXTRA NOTE: By the way I plan to learn more ruby as it is really easy, > > and is helping my RoR lots. > > Good for you. It will, given what the first ''R'' stands for! > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Aah wait. One last issue, and it IS the last problem. I can''t get it to display the URL right; basically it goes to tutorials/NextTutID and I want it to go to categories/catID/ tutorials/NextTutID In routes.rb this is the line that makes most things go like this: map.connect ''categories/:id/tutorials/:action'', :controller => ''categories'' To get it working from this I tried using this link for the link, but it didn''t seem to make a difference: <% @NextLesson = Tutorial.next_lesson(@tutorial.position, @tutorial.category_id) %> <%= link_to ''Next lesson'', @NextLesson, :controller => ''categories'', :id => (@category.id), :action => (@NextLesson) %> When I''ve used this format before I''ve used lines like this, but this technique is basically what I''ve done above, and it just isn''t changing.. <%= link_to tutorial.name, :controller => ''categories'', :id => (@category), :id => (@category.id), :action => (tutorial.id) %> I think that my routes.rb route URL system is currently bad as it randomly uses the action as the tutorial id etc, but I didn''t konw another way to do it so it''s setup this way now; Does anyone know how I can change the URL it links to from tutorials/11 (for example) to categories/1/tutorials/11 ? This is my LAST query on this topic and when it''s sorted I will have finally finished a new system I''m working on! Thanks for all your help so far guys, Please Help, Thanks In Advance, Joe On May 7, 8:11 pm, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote:> THANK YOU! > > This was the missing piece of the puzzle, with changing it to :first > and some more editing I''ve now got it to work! > > If I have any more problems I''ll probably create a new topic (unless I > get them very quickly), > > Thanks again, > > Joe > > On May 7, 7:15 pm, Michael Pavling <pavl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On 7 May 2010 16:28, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote: > > > > <%= link_to ''Next'', Tutorial.next_lesson(@tutorial.id, > > > @tutorial.category_id) %> > > > > Does anyone know why this is happening? > > > I''m only gonna reply this time because you''re being so dammed polite. > > But no more from me on this thread... > > > You''re putting the result of your class method into the link_to; the > > link_to expects a single AR object, but the method is returning an > > array of them. > > > You could test all this yourself in a console. Run your method and see > > what happens. Then either change the :all to :first, or do something > > else to get a single object (urm... I dunno... like maybe use a plugin > > that does it all for you... I''ve heard acts_as_list is good ;-) > > > > EXTRA NOTE: By the way I plan to learn more ruby as it is really easy, > > > and is helping my RoR lots. > > > Good for you. It will, given what the first ''R'' stands for! > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I''ve just tried using this in routes.rb: map.resources :tutorials, :path_prefix => ''/categories/:category_id'' However the link isn''t changing, it''s still just going to /tutorials/ ID, the above line is just making it work when I type in a URL with that format. Now I''m beggining to think that it''s possibly the link itself causing the issues, and not so much the routes.rb file. Please Help, Thanks In Advance, Joe On May 7, 8:30 pm, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote:> Aah wait. One last issue, and it IS the last problem. > > I can''t get it to display the URL right; basically it goes to > tutorials/NextTutID and I want it to go to categories/catID/ > tutorials/NextTutID > > In routes.rb this is the line that makes most things go like this: > > map.connect ''categories/:id/tutorials/:action'', :controller => > ''categories'' > > To get it working from this I tried using this link for the link, but > it didn''t seem to make a difference: > > <% @NextLesson = Tutorial.next_lesson(@tutorial.position, > @tutorial.category_id) %> > <%= link_to ''Next lesson'', @NextLesson, :controller => > ''categories'', :id => (@category.id), :action => (@NextLesson) %> > > When I''ve used this format before I''ve used lines like this, but this > technique is basically what I''ve done above, and it just isn''t > changing.. > > <%= link_to tutorial.name, :controller => ''categories'', :id => > (@category), :id => (@category.id), :action => (tutorial.id) %> > > I think that my routes.rb route URL system is currently bad as it > randomly uses the action as the tutorial id etc, but I didn''t konw > another way to do it so it''s setup this way now; Does anyone know how > I can change the URL it links to from tutorials/11 (for example) to > categories/1/tutorials/11 ? > > This is my LAST query on this topic and when it''s sorted I will have > finally finished a new system I''m working on! > > Thanks for all your help so far guys, > > Please Help, > > Thanks In Advance, > > Joe > > On May 7, 8:11 pm, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote: > > > > > THANK YOU! > > > This was the missing piece of the puzzle, with changing it to :first > > and some more editing I''ve now got it to work! > > > If I have any more problems I''ll probably create a new topic (unless I > > get them very quickly), > > > Thanks again, > > > Joe > > > On May 7, 7:15 pm, Michael Pavling <pavl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On 7 May 2010 16:28, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote: > > > > > <%= link_to ''Next'', Tutorial.next_lesson(@tutorial.id, > > > > @tutorial.category_id) %> > > > > > Does anyone know why this is happening? > > > > I''m only gonna reply this time because you''re being so dammed polite. > > > But no more from me on this thread... > > > > You''re putting the result of your class method into the link_to; the > > > link_to expects a single AR object, but the method is returning an > > > array of them. > > > > You could test all this yourself in a console. Run your method and see > > > what happens. Then either change the :all to :first, or do something > > > else to get a single object (urm... I dunno... like maybe use a plugin > > > that does it all for you... I''ve heard acts_as_list is good ;-) > > > > > EXTRA NOTE: By the way I plan to learn more ruby as it is really easy, > > > > and is helping my RoR lots. > > > > Good for you. It will, given what the first ''R'' stands for! > > > > -- > > > 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-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Bump?! This is this final step, please can anyoe help me? Thanks In Advance, Please Help, Joe On May 8, 7:33 am, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote:> I''ve just tried using this in routes.rb: > map.resources :tutorials, :path_prefix => ''/categories/:category_id'' > > However the link isn''t changing, it''s still just going to /tutorials/ > ID, the above line is just making it work when I type in a URL with > that format. > Now I''m beggining to think that it''s possibly the link itself causing > the issues, and not so much the routes.rb file. > > Please Help, > > Thanks In Advance, > > Joe > > On May 7, 8:30 pm, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote: > > > > > Aah wait. One last issue, and it IS the last problem. > > > I can''t get it to display the URL right; basically it goes to > > tutorials/NextTutID and I want it to go to categories/catID/ > > tutorials/NextTutID > > > In routes.rb this is the line that makes most things go like this: > > > map.connect ''categories/:id/tutorials/:action'', :controller => > > ''categories'' > > > To get it working from this I tried using this link for the link, but > > it didn''t seem to make a difference: > > > <% @NextLesson = Tutorial.next_lesson(@tutorial.position, > > @tutorial.category_id) %> > > <%= link_to ''Next lesson'', @NextLesson, :controller => > > ''categories'', :id => (@category.id), :action => (@NextLesson) %> > > > When I''ve used this format before I''ve used lines like this, but this > > technique is basically what I''ve done above, and it just isn''t > > changing.. > > > <%= link_to tutorial.name, :controller => ''categories'', :id => > > (@category), :id => (@category.id), :action => (tutorial.id) %> > > > I think that my routes.rb route URL system is currently bad as it > > randomly uses the action as the tutorial id etc, but I didn''t konw > > another way to do it so it''s setup this way now; Does anyone know how > > I can change the URL it links to from tutorials/11 (for example) to > > categories/1/tutorials/11 ? > > > This is my LAST query on this topic and when it''s sorted I will have > > finally finished a new system I''m working on! > > > Thanks for all your help so far guys, > > > Please Help, > > > Thanks In Advance, > > > Joe > > > On May 7, 8:11 pm, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote: > > > > THANK YOU! > > > > This was the missing piece of the puzzle, with changing it to :first > > > and some more editing I''ve now got it to work! > > > > If I have any more problems I''ll probably create a new topic (unless I > > > get them very quickly), > > > > Thanks again, > > > > Joe > > > > On May 7, 7:15 pm, Michael Pavling <pavl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On 7 May 2010 16:28, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote: > > > > > > <%= link_to ''Next'', Tutorial.next_lesson(@tutorial.id, > > > > > @tutorial.category_id) %> > > > > > > Does anyone know why this is happening? > > > > > I''m only gonna reply this time because you''re being so dammed polite. > > > > But no more from me on this thread... > > > > > You''re putting the result of your class method into the link_to; the > > > > link_to expects a single AR object, but the method is returning an > > > > array of them. > > > > > You could test all this yourself in a console. Run your method and see > > > > what happens. Then either change the :all to :first, or do something > > > > else to get a single object (urm... I dunno... like maybe use a plugin > > > > that does it all for you... I''ve heard acts_as_list is good ;-) > > > > > > EXTRA NOTE: By the way I plan to learn more ruby as it is really easy, > > > > > and is helping my RoR lots. > > > > > Good for you. It will, given what the first ''R'' stands for! > > > > > -- > > > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > 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-talk-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
youtube-T/oTI28FLjDQXOPxS62xeg@public.gmane.org
2010-May-10 06:19 UTC
Re: Finding the next item, in a group of items.
Y''know I think this topic is too long anyway, so I''m probably going to create a new topic on the issue tonight (unless someone wants to reply between now and then). Thanks For Your Help Guys! Joe On May 9, 4:43 pm, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote:> Bump?! This is this final step, please can anyoe help me? > > Thanks In Advance, > > Please Help, > > Joe > > On May 8, 7:33 am, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote: > > > > > I''ve just tried using this in routes.rb: > > map.resources :tutorials, :path_prefix => ''/categories/:category_id'' > > > However the link isn''t changing, it''s still just going to /tutorials/ > > ID, the above line is just making it work when I type in a URL with > > that format. > > Now I''m beggining to think that it''s possibly the link itself causing > > the issues, and not so much the routes.rb file. > > > Please Help, > > > Thanks In Advance, > > > Joe > > > On May 7, 8:30 pm, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote: > > > > Aah wait. One last issue, and it IS the last problem. > > > > I can''t get it to display the URL right; basically it goes to > > > tutorials/NextTutID and I want it to go to categories/catID/ > > > tutorials/NextTutID > > > > In routes.rb this is the line that makes most things go like this: > > > > map.connect ''categories/:id/tutorials/:action'', :controller => > > > ''categories'' > > > > To get it working from this I tried using this link for the link, but > > > it didn''t seem to make a difference: > > > > <% @NextLesson = Tutorial.next_lesson(@tutorial.position, > > > @tutorial.category_id) %> > > > <%= link_to ''Next lesson'', @NextLesson, :controller => > > > ''categories'', :id => (@category.id), :action => (@NextLesson) %> > > > > When I''ve used this format before I''ve used lines like this, but this > > > technique is basically what I''ve done above, and it just isn''t > > > changing.. > > > > <%= link_to tutorial.name, :controller => ''categories'', :id => > > > (@category), :id => (@category.id), :action => (tutorial.id) %> > > > > I think that my routes.rb route URL system is currently bad as it > > > randomly uses the action as the tutorial id etc, but I didn''t konw > > > another way to do it so it''s setup this way now; Does anyone know how > > > I can change the URL it links to from tutorials/11 (for example) to > > > categories/1/tutorials/11 ? > > > > This is my LAST query on this topic and when it''s sorted I will have > > > finally finished a new system I''m working on! > > > > Thanks for all your help so far guys, > > > > Please Help, > > > > Thanks In Advance, > > > > Joe > > > > On May 7, 8:11 pm, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote: > > > > > THANK YOU! > > > > > This was the missing piece of the puzzle, with changing it to :first > > > > and some more editing I''ve now got it to work! > > > > > If I have any more problems I''ll probably create a new topic (unless I > > > > get them very quickly), > > > > > Thanks again, > > > > > Joe > > > > > On May 7, 7:15 pm, Michael Pavling <pavl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > On 7 May 2010 16:28, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote: > > > > > > > <%= link_to ''Next'', Tutorial.next_lesson(@tutorial.id, > > > > > > @tutorial.category_id) %> > > > > > > > Does anyone know why this is happening? > > > > > > I''m only gonna reply this time because you''re being so dammed polite. > > > > > But no more from me on this thread... > > > > > > You''re putting the result of your class method into the link_to; the > > > > > link_to expects a single AR object, but the method is returning an > > > > > array of them. > > > > > > You could test all this yourself in a console. Run your method and see > > > > > what happens. Then either change the :all to :first, or do something > > > > > else to get a single object (urm... I dunno... like maybe use a plugin > > > > > that does it all for you... I''ve heard acts_as_list is good ;-) > > > > > > > EXTRA NOTE: By the way I plan to learn more ruby as it is really easy, > > > > > > and is helping my RoR lots. > > > > > > Good for you. It will, given what the first ''R'' stands for! > > > > > > -- > > > > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > > 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-talk@googlegroups.com. > > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > 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-talk-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.