Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 搜掠搜索缺少一个参数_Ruby On Rails_Ruby On Rails 4_Ransack - Fatal编程技术网

Ruby on rails 搜掠搜索缺少一个参数

Ruby on rails 搜掠搜索缺少一个参数,ruby-on-rails,ruby-on-rails-4,ransack,Ruby On Rails,Ruby On Rails 4,Ransack,我正在尝试使用rails上的ransack创建搜索表单。我遇到了一个小问题 我犯了一个错误 参数丢失或值为空:信息 当我提交搜索时 信息_controller.rb class InformationController < ApplicationController before_action :set_information, only: [:show, :edit, :update, :destroy] respond_to :html # Add the

我正在尝试使用rails上的ransack创建搜索表单。我遇到了一个小问题

我犯了一个错误

参数丢失或值为空:信息

当我提交搜索时

信息_controller.rb

    class InformationController < ApplicationController
  before_action :set_information, only: [:show, :edit, :update, :destroy]

  respond_to :html
    # Add the breadcrumbs
require 'uri'



  # User must authenticate to use all actions in the users controller  
  before_filter :authenticate_user!, except: [ :home, :show, :splash]

  def index

    @search = Information.search(params[:q])
 @information  = params[:distinct].to_i.zero? ?
 @search.result :
@search.result(distinct: true)
@information = @information.page(params[:page]).per(10)
respond_with @information
  end


  def admin
        @search = Information.search(params[:q])
    @information = @search.result
    @search.build_condition
  end


#def search
#@q = Information.ransack(params[:q])
#@information = @q.result(distinct: true)
#end




  # GET /information/1
  # GET /information/1.json
  def show
    session[:return_to] = request.fullpath
  end

  # GET /information/new
  def new
    @information = Information.new
  end

  # GET /information/1/edit
  def edit
  end

  # POST /information
  # POST /information.json
  def create
    @information = Information.new(information_params)

    respond_to do |format|
      if @information.save
        format.html { redirect_to @information, notice: 'Entry was successfully created.' }
        format.json { render :show, status: :created, location: @information }
      else
        format.html { render :new }
        format.json { render json: @information.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /information/1
  # PATCH/PUT /information/1.json
  def update
    respond_to do |format|
      if @information.update(information_params)
        format.html { redirect_to @information, notice: 'Entry was successfully updated.' }
        format.json { render :show, status: :ok, location: @information }
      else
        format.html { render :edit }
        format.json { render json: @information.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /information/1
  # DELETE /information/1.json
  def destroy
    @information.destroy
    respond_to do |format|
      format.html { redirect_to information_index_url, notice: 'Entry was successfully removed.' }
      format.json { head :no_content }
    end
  end





  private
    # Use callbacks to share common setup or constraints between actions.
    def set_information
      @information = Information.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def information_params
      params.require(:information).permit(:name, :description, :show, :date, :heading, :subheading, :image, :places, :data_type, :reference)
    end
end

多谢各位。如果您需要更多详细信息,请询问:^)

猜测
params[:信息]
is
nil
提交表单时,将视图中的搜索字段关联起来,以便available@Nithin它提交:请求参数:{“utf8”=>“✓", "真实性标志“=>”ZZGN1PWBJJSDDMVZA1PEBJO1OX4MYNISSYQUNQJKSNBH9FNXDWVAFR‌​sBTOFwDz9x9cie8pYSUqIHUqvB/BQ==”,“q”=>{“date\u gteq”=>,“date\u lteq”=>,“name\u cont”=>“name”},“commit”=>“Search”}但我仍然得到了错误
<%= search_form_for(
 @search,
 :url => admin_index_path,
 html: { method: :post }
 ) do |f| %>
  <%= f.condition_fields do |c| %>
    <%= render "condition_fields", f: c%>
  <% end %>
  <p><%= link_to_add_fields "Add Conditions", f, :condition %>
  <div class="actions"><%= f.submit "Search" %></div>
<% end %>
Rails.application.routes.draw do

 root :to => 'information#splash'


   devise_for :users, :skip => [:sessions], :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
  as :user do
    get 'signin' => 'devise/sessions#new', :as => :new_user_session
    post 'signin' => 'devise/sessions#create', :as => :user_session
    delete 'signout' => 'devise/sessions#destroy', :as => :destroy_user_session
  end

##########################################
#                ADMIN                   #
##########################################
#admin panel
  get '/admin' => 'information#admin'
  #get '/admin/new' => 'information'
resources :information, path: '/admin'


get '/home/:id', to: 'information#show'

get 'home' => 'information#index', :as => :home
 concern :paginatable do
    get '(page/:page)', :action => :index, :on => :collection, :as => ''
  end
   concern :paginatable do
    get '(page/:page)', :action => :information, :on => :collection, :as => ''
  end

  #get '/new' => 'information#new'
  #get '/public' => 'information#'

##########################################################  

  resources :information 
  resources :admin
end