2015-03-03 24 views
0

,當我嘗試使用的形式提供的參數來拯救我的無表格模型我得到這個錯誤:無表型號 - 從形式創建對象NoMethodError PARAMS

error message

用戶是我的色器件模型。我不知道錯誤來自哪裏,原因是什麼。我不應該投日期或其他。

我創建使用ActiveRecord Tableless寶石無表型號:

class Search < ActiveRecord::Base 
    has_no_table 

    column :start_date, :date 
    column :end_date, :date 
    column :smart, :boolean 
end 

我的形式:

<%= form_for @search, url: {controller: 'search', action: 'search'} do |s| %> 
     <%= s.hidden_field :smart, :value => false %> 

     <div class='col-md-4'> 
     <div class="form-group"> 
      <div class='input-group'> 
      <%= s.text_field :start_date, class: 'form-control', required: true %> 
      <span class="input-group-addon"><i class="fa fa-calendar"></i></span> 
      </div> 
     </div> 
     </div> 

     <div class='col-md-4'> 
     <div class="form-group"> 
      <div class='input-group'> 
      <%= s.text_field :end_date, class: 'form-control', required: true %> 
      <span class="input-group-addon"><i class="fa fa-calendar"></i></span> 
      </div> 
     </div> 
     </div> 

     <div class="col-md-1"> 
     <%= button_tag 'Search', class: 'btn btn-success' %> 
     </div> 
    <% end %> 

我的控制,我得到的錯誤:

class SearchController < ApplicationController 
    def search 
    @search = Search.new(search_params) 

    puts params 
    puts @search.as_json.to_s 
    end 

    private 
    def search_params 
    params.require(:search).permit(:start_date, :end_date, :smart) 
    end 
end 

我使用這是我的表單的一個模型,因爲我希望它在將來與其他模型具有多對一的關聯。

更新

由於alexcavalli指出,這是用ActiveRecord無表寶石的問題。票可以發現here

+0

訪問「搜索」頁面或提交表單後顯示此錯誤嗎? – 2015-03-03 11:41:55

+0

在表單提交中,我調用搜索方法。所以在提交。 – m3dw3 2015-03-03 12:03:49

回答

0

它看起來像from_user該方法名稱的一部分與設計無關。這只是一個ActiveRecord方法。

http://www.rubydoc.info/github/rails/rails/ActiveRecord/Type/Value:type_cast_from_user

有一個開放的問題,與無表寶石和Rails 4.2 https://github.com/softace/activerecord-tableless/issues/22#issuecomment-67742177

或者也有一些信息,這可能是由於Postgres的適配器

This issue still exists when using Postgresql (pg) adapter. I get errors when using :string. Have been able to work around this by using :varchar

你可能會最好在那裏提交一個錯誤報告和/或嘗試一個稍微老一點的Rails版本。祝你好運!

+0

謝謝,我會檢查一下。 – m3dw3 2015-03-03 19:33:54

相關問題