ruby - Couldn't find [Model] without an ID - ransack - rails 4 -


i'm new rails , appreciated.

i implemented gem ransack , whenever click on search button of app error stated below image

enter image description here

i have below error in terminal:

started "/adverts?utf8=%e2%9c%93&q%5btitle_cont%5d=accountant&commit=search" 127.0.0.1 @ 2015-06-13 20:17:47 +0100 processing advertscontroller#index html   parameters: {"utf8"=>"✓", "q"=>{"title_cont"=>"accountant"}, "commit"=>"search"} completed 404 not found in 4ms (activerecord: 0.7ms)  activerecord::recordnotfound (couldn't find userr without id):   app/controllers/adverts_controller.rb:16:in `index' 

i unsure why above error , why pointing me index action of advert_controller.rb , not pointing searchpg action of static_pages_controller.rb

any or advise on broadening understanding error on appreciated. have below codings

adverts_controller.rb

class advertscontroller < applicationcontroller   respond_to :html, :xml, :json   before_action :set_advert, only: [:show, :edit, :update, :destroy]    def index     @userr = userr.find(params[:userr_id])     @adverts = @userr.adverts.order("created_at desc")     respond_with(@adverts)   end    def show ...   end    def new ...   end    def edit ...   end    def create ...   end    def update ...   end    def destroy ...   end end 

static_pages_controller.rb

class staticpagescontroller < applicationcontroller   respond_to :html, :xml, :json   def searchpg     @search = advert.search(params[:q])     @adverts = @search.result   end  end 

routes.rb

rails.application.routes.draw    resources :contacts,  only: [:new, :create]   'contact',       to: 'contacts#new'    resources :forms    devise_for :userrs   resources :userrs     resources :adverts     member       'applicants'     end   end    root    'static_pages#homepg'       'search',                 to: 'static_pages#searchpg' end 

views/static_pages/searchpg.html.erb

<h1>search jobs</h1> <p>find me in app/views/static_pages/approachpg.html.erb</p>  <div>   <%= search_form_for(@search) |f| %>     <%= f.label :title_cont %>     <%= f.text_field :title_cont %>     <%= f.submit 'search' %>   <% end %> </div></br>  <div>   <table>     <thead>       <tr>         <th>published</th>         <th>title</th>         <th>content</th>         <th>city</th>         <th>town</th>         <th>postcode</th>         <th></th>       </tr>     </thead>      <tbody>       <% @adverts.each |advert| %>         <tr>           <td><%= advert.created_at.strftime("%b %d, %y") %></td>           <td><%= link_to advert.title, userr_advert_path(advert.userr, advert) %></td>           <td><%= advert.content %></td>           <td><%= advert.city %></td>           <td><%= advert.town %></td>           <td><%= advert.postcode %></td>           <td><%= link_to 'apply now', userr_advert_path(advert.userr, advert) %></td>         </tr>       <% end %>     </tbody>   </table> </div>  

advert attributes:

2.1.2 :001 > advert.new  => #<advert id: nil, title: nil, content: nil, category_jobtype_id: nil, category_positiontype_id: nil, salarystart: nil, salaryend: nil, category_country_id: nil, city: nil, town: nil, postcode: nil, category_editorialapproval_id: nil, category_applicationrequest_id: nil, created_at: nil, updated_at: nil, userr_id: nil, category_advert_id: nil>  2.1.2 :002 > 

advert.rb [model]

class advert < activerecord::base   belongs_to :category_jobtype   belongs_to :category_positiontype   belongs_to :category_country   belongs_to :category_editorialapproval   belongs_to :category_applicationrequest   belongs_to :category_advert   belongs_to :userr   has_many :forms   has_many :userjs, through: :forms end 


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -