I''m a reasonably well-versed PHP user who decided to look at rails because I have a big project, a faculty roster database, to put up in about a month. The first step was easy. The second and third steps are hard. Things that you can do inline in PHP, like control flow, don''t work in rails. I couldn''t get my template to set background color for table cells based on a database value. Any suggestions? Jason Green green-FWpEgXUGHwo@public.gmane.org <mailto:green-FWpEgXUGHwo@public.gmane.org> Distance Education Coordinator/Instructional Design Specialist Dyersburg State Community College (731) 286-3279 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
I use partial templates. Then set the CSS class based on some criteria. So, in the main view page do something like ... <% render_collection_of_partials, ''teachers'', @teachers %> ... And in the _teachers.rhtml partial: <% c = @teacher.isTenure ? ''tenure'' : ''non-tenure'' %> <tr class="<%= c %>"> <td><%= teacher.name %> </tr> That should give you the basic idea (less any typos, etc). -Dale On Tue, 15 Mar 2005 13:16:08 -0600, Green, Jason <green-FWpEgXUGHwo@public.gmane.org> wrote:> > > > I''m a reasonably well-versed PHP user who decided to look at rails because I > have a big project, a faculty roster database, to put up in about a month. > The first step was easy. The second and third steps are hard. Things that > you can do inline in PHP, like control flow, don''t work in rails. I > couldn''t get my template to set background color for table cells based on a > database value. Any suggestions? > > > > > > Jason Green > green-FWpEgXUGHwo@public.gmane.org > > Distance Education Coordinator/Instructional Design Specialist > > Dyersburg State Community College > > (731) 286-3279 > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- All creativity is an extended form of a joke. - Alan Kay
On 15.3.2005, at 21:16, Green, Jason wrote:> I’m a reasonably well-versed PHP user who decided to look at rails > because I have a big project, a faculty roster database, to put up in > about a month. The first step was easy. The second and third steps > are hard. Things that you can do inline in PHP, like control flow, > don’t work in rails.Could you elaborate a bit more on this? Like Dale proposed, the problem below is easily solved and I really don''t think about anything you can do with PHP but not with Rails. If you have any other problems besides the one, just post them here (or ask for help on #rubyonrails) and I''m sure we can figure out a way to solve them. //jarkko> I couldn’t get my template to set background color for table cells > based on a database value. Any suggestions? > > > > > > Jason Green > green-FWpEgXUGHwo@public.gmane.org > > Distance Education Coordinator/Instructional Design Specialist > > Dyersburg State Community College > > (731) 286-3279 > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Tue, 15 Mar 2005 13:16:08 -0600, Green, Jason <green-FWpEgXUGHwo@public.gmane.org> wrote:> I''m a reasonably well-versed PHP user who decided to look at rails because I > have a big project, a faculty roster database, to put up in about a month. > The first step was easy. The second and third steps are hard. Things that > you can do inline in PHP, like control flow, don''t work in rails. I > couldn''t get my template to set background color for table cells based on a > database value. Any suggestions?Can you elaborate on what you''re trying to do? The way you''ve described it, it doesn''t sound at all hard (like 5mins of work, tops). The way I understand your problem (which I admit could very well be incorrect), you''ve got a field in your database, and you want to set the background color based on the value in this field. So in your list.rhtml you''ve got something like this: <% for row in @rows %> <tr> <td><%= row.field1 %></td> <td><%= row.field2 %></td> [... etc ...] </tr> <% end %> So if you want to set the background color for the table row, just do this: <% for row in @rows %> <tr class="<%= row.color %>"> <td><%= row.field1 %></td> <td><%= row.field2 %></td> [... etc ...] </tr> <% end %> And then in your CSS file, you''d make a class for all the possible values of your "color" field in your db table, which would look like this: .foo { background-color: red } .bar { background-color: blue} [etc] I hope this points you in the right direction. The examples above are of course oversimplified, "@rows" will actually be whatever the name of your model is, like "@professors" or "@faculty" or whatever you''re using, the ".color" in "row.color" would be whatever field you''re trying to color based on, ".foo" and ".bar" would be possible values of that field. To make a more concrete example, I''d need to see your proper db schema, what you''re trying to color based on, and some sample data. -- One Guy With A Camera http://rbpark.ath.cx
> On Tue, 15 Mar 2005 13:16:08 -0600, Green, Jason <green-FWpEgXUGHwo@public.gmane.org> > wrote: >> I''m a reasonably well-versed PHP user who decided to look at rails >> because I >> have a big project, a faculty roster database, to put up in about a >> month. >> The first step was easy. The second and third steps are hard. Things >> that >> you can do inline in PHP, like control flow, don''t work in rails. I >> couldn''t get my template to set background color for table cells >> based on a >> database value. Any suggestions?Yes. What you''re trying to do is easily handled with partials. You should check out the "Four Days on Rails" tutorial at http://rails.homelinux.org which includes a section that shows exactly how to do this.