[Rails] Re: Having trouble setting up my View Page to only show Specific Data?
I would use scopes for late or "due soon" projects.
class
Project < ActiveRecord::Base
scope
:late
, -> { where("some_time_attr > ?",
Time.now
) }
end
So, then you can call the following in your Controller:
@projects = Project.late
On Thursday, January 2, 2014 6:24:05 PM UTC+1, Ruby-Forum.com User wrote:
Hello,
In my view (index.html) I have a table that calls all of my projects.
<% @projects.each do |project| %>
I created 2 methods in the Model, project.late? and project.dueSoon?
In these methods I used If Then Elsif Else Blocks to form my logic, all
based on a bunch of my date fields which determine if the project is
late or dueSoon.
I have also created a class that takes the Late and due soon methods and
adds a Color-Background style if the Specific project is valid.
<% colorClass = project.late? ? "late" : project.dueSoon? ? "dueSoon" :
"ok" %>
<td class=<%= colorClass %>><%= link_to project.product, project %></td>
All this works great in my index View. My goal now is to create a 2nd
View, delinquent.html.erb page that only returns the project(s) of
Projects.project that are Late or dueSoon.
If someone could assist me with this that would be great.
Thank You.
--
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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/367d55c7-41a8-4ac1-8891-43bdb201a388%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home