2013-09-30 19 views
0

多個日曆,我試圖讓一個應用程序,用戶可以在專門的房間(用戶的has_many約會和房​​間的has_many約會)沒有新的模式

我使用event_calendar寶石預約。這是一個簡單的寶石,但我需要的一切,顯示與約會的日曆。

但我怎麼能有一個日曆到一個房間?日曆,在這種寶石,是不是模特,所以沒有HAS_ONE的關係

我可以做這樣的事情上的routes.rb

match 'room/:id/calendar(/:year(/:month))' => 'calendar#index', :as => :calendar, :constraints => {:year => /\d{4}/, :month => /\d{1,2}/}, via: [:get] 

,並在我的日曆索引過濾器由房ID ?是這樣的:

def index 
    @month = (params[:month] || (Time.zone || Time).now.month).to_i 
    @year = (params[:year] || (Time.zone || Time).now.year).to_i 

    @shown_month = Date.civil(@year, @month) 
    @event_strips = Appointment.event_strips_for_month(@shown_month) 
    #Here is where I would filter by room id 
    @filtered = @event_strips.find(params[:id]) 
end 

我在紅寶石2和Rails 4.感謝提前

+0

所以 - 當你嘗試上面的代碼時發生了什麼? –

回答

0

你可以添加一個查找選項

Appointment.event_strips_for_month(@shown_month) 

Appointment.event_strips_for_month(@shown_month,0, {}) 

最後一個散列是你要傳入的作用域()

例如。

Appointment.event_strips_for_month(@shown_month,0, {:conditions => "id == 1"}) 

這沒有經過測試,但它是你會做的。

你可以看到它如何被使用的看着 https://github.com/elevation/event_calendar/blob/master/lib/event_calendar.rb

專門在events_for_date_range方法。

+0

完美!非常感謝你Anko! –

+0

不用擔心 - 當有疑問時,請看源代碼:)這非常容易,只有在練習時才更容易。 – Anko