I''m not sure how best to do this. I have a project that has Features (these are video links) that go into a homepage. It also has Events, which get displayed in a table, can be clicked on, and a page about that event displays. I''m working in an admin application for this site, a type of CMS system whereby the administrator can put in different videos for the homepage, and edit the events themselves. Ive been asked to add videos to the events. To do this, I am creating an EventFeature object. Thusm when someone goes to edit an event''s features, it is not like editing features for the homepage. In an EventFeature, an event_id is in place. My question then, how, in the erb for eventfeatures, can I express things like: <% if @features any? %> which now are not just if there are any features, but any eventfeatures with a specified event_id. How can I express that here? in other words <% if @eventfeatures any? %> Is not really what I want because i dont want all eventfeatures, only those where eventfeatures.event_id==specific value. Similarly, how would you express: <$ @features.each do |feature| %> to be: <$ @eventfeatures.each do |eventfeature| %> only for those eventfeatures of a specific eventfeature.event_id TIA, rvince -- 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/hSmniP0M1ucJ. For more options, visit https://groups.google.com/groups/opt_out.
On 13 November 2012 16:22, RVince <rvince99-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> I''m not sure how best to do this. I have a project that has Features (these > are video links) that go into a homepage. > It also has Events, which get displayed in a table, can be clicked on, and a > page about that event displays. > I''m working in an admin application for this site, a type of CMS system > whereby the administrator can put in different videos for the homepage, and > edit the events themselves. > > Ive been asked to add videos to the events. To do this, I am creating an > EventFeature object. Thusm when someone goes to edit an event''s features, it > is not like editing features for the homepage. In an EventFeature, an > event_id is in place. My question then, how, in the erb for eventfeatures, > can I express things like: > > <% if @features any? %> > > which now are not just if there are any features, but any eventfeatures with > a specified event_id. How can I express that here? > > in other words > > <% if @eventfeatures any? %> > > Is not really what I want because i dont want all eventfeatures, only those > where eventfeatures.event_id==specific value. > > Similarly, how would you express: > > <$ @features.each do |feature| %> > > to be: > > <$ @eventfeatures.each do |eventfeature| %> > > only for those eventfeatures of a specific eventfeature.event_idIt is not entirely clear what the questions are. I find it best to think about the problem in terms of models and relationships. It seems that you have models Feature, Event and EventFeature, where Event has_many :event_features and also has_many :features, :through => :event_features Then if you have an event then its features are event.features. So can you confirm that is correct (or not) and ask the question again? Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/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 https://groups.google.com/groups/opt_out.
Colin, no, events and features have no relationship to each other (Eventfeatures are like features, but they are a separate object here). So: Event has_many : evenfeatures and Eventfeature belongs_to: event Thanks! rvince On Tuesday, November 13, 2012 11:22:30 AM UTC-5, RVince wrote:> > I''m not sure how best to do this. I have a project that has Features > (these are video links) that go into a homepage. > It also has Events, which get displayed in a table, can be clicked on, and > a page about that event displays. > I''m working in an admin application for this site, a type of CMS system > whereby the administrator can put in different videos for the homepage, and > edit the events themselves. > > Ive been asked to add videos to the events. To do this, I am creating an > EventFeature object. Thusm when someone goes to edit an event''s features, > it is not like editing features for the homepage. In an EventFeature, an > event_id is in place. My question then, how, in the erb for eventfeatures, > can I express things like: > > <% if @features any? %> > > which now are not just if there are any features, but any eventfeatures > with a specified event_id. How can I express that here? > > in other words > > <% if @eventfeatures any? %> > > Is not really what I want because i dont want all eventfeatures, only > those where eventfeatures.event_id==specific value. > > Similarly, how would you express: > > <$ @features.each do |feature| %> > > to be: > > <$ @eventfeatures.each do |eventfeature| %> > > only for those eventfeatures of a specific eventfeature.event_id > > TIA, rvince >-- 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/KAv1fwlpQVkJ. For more options, visit https://groups.google.com/groups/opt_out.
On 13 November 2012 17:02, RVince <rvince99-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> Colin, no, events and features have no relationship to each other > (Eventfeatures are like features, but they are a separate object here). So: > > Event has_many : evenfeatures > > and > > Eventfeature belongs_to: eventSo why were you telling us about Features then? Can you try to ask the question again then? You know that if you have an event then its eventfeatures are event.eventfeatures and if you have an eventfeature then its event is eventfeature.event? Colin> > Thanks! rvince > > > > On Tuesday, November 13, 2012 11:22:30 AM UTC-5, RVince wrote: >> >> I''m not sure how best to do this. I have a project that has Features >> (these are video links) that go into a homepage. >> It also has Events, which get displayed in a table, can be clicked on, and >> a page about that event displays. >> I''m working in an admin application for this site, a type of CMS system >> whereby the administrator can put in different videos for the homepage, and >> edit the events themselves. >> >> Ive been asked to add videos to the events. To do this, I am creating an >> EventFeature object. Thusm when someone goes to edit an event''s features, it >> is not like editing features for the homepage. In an EventFeature, an >> event_id is in place. My question then, how, in the erb for eventfeatures, >> can I express things like: >> >> <% if @features any? %> >> >> which now are not just if there are any features, but any eventfeatures >> with a specified event_id. How can I express that here? >> >> in other words >> >> <% if @eventfeatures any? %> >> >> Is not really what I want because i dont want all eventfeatures, only >> those where eventfeatures.event_id==specific value. >> >> Similarly, how would you express: >> >> <$ @features.each do |feature| %> >> >> to be: >> >> <$ @eventfeatures.each do |eventfeature| %> >> >> only for those eventfeatures of a specific eventfeature.event_id >> >> TIA, rvince > > -- > 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 > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/KAv1fwlpQVkJ. > > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/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 https://groups.google.com/groups/opt_out.
On Tuesday, November 13, 2012 12:16:15 PM UTC-5, Colin Law wrote:> > You know that if you have > an event then its eventfeatures are event.eventfeatures and if you > have an eventfeature then its event is eventfeature.event? > >Ah, it''s coming back to me now, yes, you''ve put me on the right track. But in my EventfeaturesConroller, how do I access the Event that the Eventfeature belongs to? class Admin::EventfeaturesController < Admin::AdminController def index @eventfeatures = Eventfeature.all(:order => ["feature_type,sort_order"]) end I want @eventfeatures to be only those eventfeatures that belong to the given event -- how do you specify that (or is it implied by the Eventfeature model wherein I say it belongs_to :event) ? Thanks for your help here. rvince -- 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/KYYg0otalhkJ. For more options, visit https://groups.google.com/groups/opt_out.
On 13 November 2012 17:30, RVince <rvince99-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> > > On Tuesday, November 13, 2012 12:16:15 PM UTC-5, Colin Law wrote: >> >> You know that if you have >> an event then its eventfeatures are event.eventfeatures and if you >> have an eventfeature then its event is eventfeature.event? >> > > Ah, it''s coming back to me now, yes, you''ve put me on the right track. But > in my EventfeaturesConroller, how do I access the Event that the > Eventfeature belongs to? > > class Admin::EventfeaturesController < Admin::AdminController > def index > @eventfeatures = Eventfeature.all(:order => ["feature_type,sort_order"]) > end > > I want @eventfeatures to be only those eventfeatures that belong to the > given event -- how do you specify that (or is it implied by the Eventfeature > model wherein I say it belongs_to :event) ?How do you know (in the controller) which event you are referring to? Are you passing it in the url? If you pass the event id in the url then you can fetch the event from the database and then its eventfeatures are @event.eventfeatures. Can I suggest that it might be worth your while working right through a rails tutorial such as railstutorial.org (which is free to use online) then you will get a working knowledge of the basics of Rails. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/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 https://groups.google.com/groups/opt_out.
Thanks Colin, Yeah, I better do that. I''m not a newbie, BUT I haven;t been on an RoR project since 09 (just all Python and Java in the interim) and the "Magic" of things like ActiveRecord I have forgotten about, not to mention much of the syntax. Thanks for your help here. rvince On Tuesday, November 13, 2012 3:31:07 PM UTC-5, Colin Law wrote:> > On 13 November 2012 17:30, RVince <rvin...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org <javascript:>> > wrote: > > > > > > On Tuesday, November 13, 2012 12:16:15 PM UTC-5, Colin Law wrote: > >> > >> You know that if you have > >> an event then its eventfeatures are event.eventfeatures and if you > >> have an eventfeature then its event is eventfeature.event? > >> > > > > Ah, it''s coming back to me now, yes, you''ve put me on the right track. > But > > in my EventfeaturesConroller, how do I access the Event that the > > Eventfeature belongs to? > > > > class Admin::EventfeaturesController < Admin::AdminController > > def index > > @eventfeatures = Eventfeature.all(:order => > ["feature_type,sort_order"]) > > end > > > > I want @eventfeatures to be only those eventfeatures that belong to the > > given event -- how do you specify that (or is it implied by the > Eventfeature > > model wherein I say it belongs_to :event) ? > > How do you know (in the controller) which event you are referring to? > Are you passing it in the url? If you pass the event id in the url > then you can fetch the event from the database and then its > eventfeatures are @event.eventfeatures. > > Can I suggest that it might be worth your while working right through > a rails tutorial such as railstutorial.org (which is free to use > online) then you will get a working knowledge of the basics of Rails. > > Colin >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/IkPE8j6KLlsJ. For more options, visit https://groups.google.com/groups/opt_out.