作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有事件模型。我有 3 个链接作为过去事件、即将发生的事件和当前事件。
这 3 个链接被路由到 events_url 即索引操作和 den 到索引 View 。
以下是事件 Controller 索引操作的代码...
def index
@today = Event.find (:all, :conditions => ['(start_date = current_date)'], :order => 'start_date ')
@past = Event.find (:all, :conditions => ['start_date < ?', current_date], :order => 'start_date')
@events = Event.find( :all, :conditions => ['start_date > ?', current_date], :order => 'start_date')
end
- content_for :title do
Listing Events
- content_for :div do
Listing Events
- content_for :brand_img do
%img{:src => "images/lifestyle.gif", :height => "35"}
- @events.each do |event|
%ol.hoverbox
%li.increase
= link_to image_tag(event.photo.url), event_path(event)
.abc
= event.name
%br/
.bca
= event.start_date
|
= event.start_time
/|
/= link_to " ".html_safe, event_path(event), :method => :delete, :class => "del-16", :confirm=>"Are u sure?", :title => "Delete", :style => "text-decoration:none;"
最佳答案
您可以使用查询参数来执行此操作:您只需将附加参数传递给 link_to 方法,例如:
<%= link_to "Past events", events_path(view: "past") %>
<%= link_to "Today's events", events_path(view: "today") %>
<%= link_to "All events", events_path %>
def index
case params[:view]
when 'past'
@past = Event.find (:all, :conditions => ['start_date < ?', current_date], :order => 'start_date')
when 'today'
@today = Event.find (:all, :conditions => ['(start_date = current_date)'], :order => 'start_date ')
else
@events = Event.find( :all, :conditions => ['start_date > ?', current_date], :order => 'start_date')
end
end
resources :events do
collection do
get 'past'
get 'today'
end
end
def index
@events = Event.find( :all, :conditions => ['start_date > ?', current_date], :order => 'start_date')
end
def past
@events = Event.find (:all, :conditions => ['start_date < ?', current_date], :order => 'start_date')
end
def today
@events = Event.find (:all, :conditions => ['(start_date = current_date)'], :order => 'start_date ')
end
<%= link_to "Today's events", todays_event_path %>
<%= link_to "Past events", past_event_path %>
<%= link_to "All events", event_path %>
关于ruby-on-rails - 如何将不同链接上的不同数据从同一操作传递到同一 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10382186/
我是一名优秀的程序员,十分优秀!