使用表单时无法获取url参数

时间:2016-05-18 04:23:52

标签: ruby-on-rails haml

我正在处理一个项目,不幸的是,这个特定的部分并没有使用标准的Rails路由。现在,出于某种原因,每当我的表单被激活时,我都无法再获取url params。谁知道为什么?

控制器

class ActivityController < ApplicationController
  before_action :authenticate_user!
  before_action :authorize_user

  def individual
    # individual?influencer_id=1613&start_date=&filter=last_200&format=js&mode=new&page=1&type=influencer&_=1463473352231
    @influencer_id = params[:influencer_id]
    filters = [:publisher, :pub_date, :topic_name]
    @page = params[:page].present? ? params[:page]: 1

    if filters & params.keys
      search = {}
      @influencer_id = search[:influencer_id] = params[:influencer_id] if params[:influencer_id].present?
      @publisher = search[:publisher] = params[:publisher] if params[:publisher].present? && "all" != params[:publisher]
      if params[:pub_date].present?
        start_date, end_date = params[:pub_date].split(' - ').map{ |i| DateTime.strptime(i.strip, "%m/%d/%Y")}
        @pub_date = params[:pub_date]
        search[:pub_date] = start_date..end_date
      end

      @feed = InfluencerFeed.where(influencer_id: (params[:influencer_id].to_i)).where(search).page(@page).order("pub_date DESC")
      # @feed = InfluencerFeed.where(search).page(@page).order("pub_date DESC")
    else
      @feed = InfluencerFeed.page(@page).order("pub_date DESC")
    end
    @total_pages = @feed.total_pages

    respond_to do |format|
      format.html
      format.js
    end
  end
end

查看

.fluid-row
  = render "discovery/prospect_rank", prospect: @influencer_prospect

-if (can? :individual, Activity)
  - if @feed.blank?
    .fluid-row
      .panel
    %p= "No Activity Content for this Influencer"
  - else
     .activity-feed-toolbar
      = form_tag("/activity/individual", method: "get") do
        .fluid-row
          .small-5.columns
            %h3 Activity Feed
          -if can? :filter_individual, Activity
            .small-7.columns
              .fluid-row
                .small-6.columns
                  #date_range.dates
                    %input#pub_date{name: 'pub_date', :type=>"text", :placeholder => " mm/dd/yyyy - mm/dd/yyyy", value: @pub_date}/
                %div.calendar-overlay
            .small-6.columns
              .activity-feed-filter
                -# = select_tag "activity_filter_select", options_for_select({'Last 200 Tweets' => 'last_200', 'Most Recent Relevant' => 'all', 'Relevant Twitter' => 'twitter', 'Relevant RSS' => 'rss'}), class: "filter-select"
                = hidden_field :influencer_id, value: @influencer_id
            .small-2.columns.secondary-search-filters
              = submit_tag "Apply", {:name => nil, class: 'feed-filter button', id: 'override-default-button-margin-bottom'}

.fluid-row
  .small-12.columns.no-padding.feeds-container#activity_feed_container{:data => {:page => 1}}
    = render partial: 'influencer_feed/feed', locals: {feed: @feed}

没有错误

[1] pry(#<ActivityController>)> params
=> {"influencer_id"=>"22",
 "start_date"=>"",
 "filter"=>"last_200",
 "format"=>"js",
 "mode"=>"new",
 "page"=>"1",
 "type"=>"influencer",
 "_"=>"1463545237555",
 "action"=>"individual",
 "controller"=>"activity"}

使用日历表单时出错。

[1] pry(#<ActivityController>)> params
=> {"utf8"=>"✓",
 "pub_date"=>"02/27/2016 - 02/29/2016",
 "action"=>"individual",
 "controller"=>"activity"}

0 个答案:

没有答案