Passing JQuery Datepicker Data to Rails Controller

后端 未结 1 1362
梦毁少年i
梦毁少年i 2021-01-07 14:13

I\'m new to Rails and JQuery so I\'ll try to explain this as best I can. I\'m trying to pass my JQuery datepicker values to my rails controller. The page has data on it tha

相关标签:
1条回答
  • 2021-01-07 15:07

    From your log data, this is in the Parameters:

    "event"=>{"start_date"=>"12/06/12", "end_date"=>"12/13/12"}
    

    which means start_date and end_date are in a Hash called event, so your controller should look like this:

    def dateFilter
        eventIn = params[:event]
        @events = Event.find(:all, :conditions => ["EVENT_DATE_TIME_LOCAL BETWEEN ? AND ?", eventIn[:start_date], eventIn[:end_date]])
    
        respond_to do |format|
           format.html
           format.json { render json: @events }
           format.js
        end
    end
    

    One other small thing - the form_tag class should be set like so:

    <%= form_tag({:controller => 'events', :action => 'dateFilter'}, :class => 'date_form', :remote => true) do %>
    
    0 讨论(0)
提交回复
热议问题