2015-02-11 23 views
0

我有一個表格設置爲取日期時間值。然後將該值作爲參數發送到我的控制器方法「bookingdate」中,在此處將與預訂中的其他日期進行比較,以確保沒有使用do循環的雙重預訂。如何在我的控制器中執行操作後重定向?

但是,當我提交日期形式,而不是重定向到下一個表單,其中用戶選擇其他細節,它會引發錯誤或重定向錯誤。

這裏是我的控制器

def bookingdate 

    @bookings = Booking.all 
    @bookings.each do |b| 
    if b.startdatetime == params[:startdatetime] 
     @musicians = Musician.where (["id != ?", b.musician_id]) 
    end 
    end 

    render :action => 'new' 
end 

這裏是我的路線

match '/bookdate', :to => 'bookings#bookingdate' 

回答

1

添加redirect_to幫手,並傳遞到進度

def bookingdate 

    @bookings = Booking.all 
    @bookings.each do |b| 
    if b.startdatetime == params[:startdatetime] 
     @musicians = Musician.where (["id != ?", b.musician_id]) 
    end 
    end 

    redirect_to path_where_you_want_to_redirect 
end 

我猜你想進行一些檢查路線,如果用戶有正確的填寫表格

def bookingdate 

    @bookings = Booking.all 
    @bookings.each do |b| 
    if b.startdatetime == params[:startdatetime] 
     @musicians = Musician.where (["id != ?", b.musician_id]) 
    end 
    end 
    if condition_successful 
    redirect_to path_where_you_want_to_redirect 
    else 
    render :bookingdate 
    end 
end 
+0

Hey Nermin,感謝您的快速回復。但是,當用戶選擇一個表單上的日期並按提交時,我希望它執行do循環,然後重定向到另一個表單。當我有路由'redirect_to bookings_new_path,它給了我一個未定義的局部變量/方法錯誤。思考? – 2015-02-11 14:02:21

+0

你甚至有'bookings_new_path',在控制檯'耙路線'中運行,並檢查路線是否存在 – Nermin 2015-02-11 14:24:05

+0

我有預訂/新耶 – 2015-02-11 14:31:45

相關問題