There''s an example in the book that presents a search form , listing users and their favorite languages below it. Using the search form text field you can filter the list by their favorite language. I did the demo from the book using the same schema and it works. However, I''m trying to implement this same thing in my app which uses REST controllers, and am running into an error when loading the search form. The error is: ActiveRecord::RecordNotFound in PositionsController#show Couldn''t find Position with ID=search_position I''m assuming the issue is in the search action in the controller. The list.rhtml should return all the positions. It all looks pretty straight forward. In the controller: def search unless params[:search].blank? @position_pages, @positions = paginate :positions, :per_page => 10, :order => order_from_params, :conditions => Position.conditions_by_like(params[:search]) logger.info @positions.size else list end render :partial => ''search'', :layout => false end I''m showing the get/show in the controller - though I''m not sure if or why it would intefere with the search action. def show @position = Position.find(params[:id]) respond_to do |format| format.html # show.rhtml format.xml { render :xml => @position.to_xml } end end Stuart -- http://en.wikipedia.org/wiki/Dark_ambient --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
I was having a problem like this recently. I believe it''s a problem in your routing, because params[:search] is returning ''search_position'' instead of the value you want. Have a look at the params that are being received by your action when you call the URL. Jason Dark Ambient wrote:> There''s an example in the book that presents a search form , listing > users and their favorite languages below it. Using the search form > text field you can filter the list by their favorite language. > > I did the demo from the book using the same schema and it works. > However, I''m trying to implement this same thing in my app which uses > REST controllers, and am running into an error when loading the search > form. The error is: > > ActiveRecord::RecordNotFound in PositionsController#show > Couldn''t find Position with ID=search_position > > I''m assuming the issue is in the search action in the controller. The > list.rhtml should return all the positions. It all looks pretty > straight forward. > In the controller: > > def search > unless params[:search].blank? > @position_pages, @positions = paginate :positions, > :per_page => 10, > :order => order_from_params, > :conditions => Position.conditions_by_like(params[:search]) > logger.info <http://logger.info> @positions.size > else > list > end > > render :partial => ''search'', :layout => false > end > > I''m showing the get/show in the controller - though I''m not sure if or > why it would intefere with the search action. > def show > @position = Position.find(params[:id]) > > respond_to do |format| > format.html # show.rhtml > format.xml { render :xml => @position.to_xml } > end > end > > Stuart > -- > http://en.wikipedia.org/wiki/Dark_ambient > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 10/3/06, Jason Norris <jasonmnorris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > I was having a problem like this recently. I believe it''s a problem in > your routing, because params[:search] is returning ''search_position'' > instead of the value you want. Have a look at the params that are being > received by your action when you call the URL. > > JasonNot entirely sure what I''m seeing in the log but this is the select statement going out: Parameters: {"action"=>"show", "id"=>"search_position", "controller"=>"positions"} [4;36;1mUser Columns (0.000000) [0;1mSHOW FIELDS FROM users [4;35;1mUser Load (0.000000) SELECT * FROM users WHERE (users.`id` = 11 ) LIMIT 1 [4;36;1mPosition Columns (0.000000) [0;1mSHOW FIELDS FROM positions [4;35;1mPosition Load (0.000000) SELECT * FROM positions WHERE (positions.id = 0) In the def index action I am filtering show by user. I guess at this point that is just an aside since /positions will return all the records of that user and I also can remove that condition. Which didn''t help. What I see here is the odd statement "WHERE (positions.id = 0) Not sure how the routing would effect things. Currently my routes.rb are fairly simple. map.resources :users, :sessions, :companies map.resources :positions, :member => {:description => :get} Stuart Dark Ambient wrote:> > There''s an example in the book that presents a search form , listing > > users and their favorite languages below it. Using the search form > > text field you can filter the list by their favorite language. > > > > I did the demo from the book using the same schema and it works. > > However, I''m trying to implement this same thing in my app which uses > > REST controllers, and am running into an error when loading the search > > form. The error is: > > > > ActiveRecord::RecordNotFound in PositionsController#show > > Couldn''t find Position with ID=search_position > > > > I''m assuming the issue is in the search action in the controller. The > > list.rhtml should return all the positions. It all looks pretty > > straight forward. > > In the controller: > > > > def search > > unless params[:search].blank? > > @position_pages, @positions = paginate :positions, > > :per_page => 10, > > :order => order_from_params, > > :conditions => Position.conditions_by_like(params[:search]) > > logger.info <http://logger.info> @positions.size > > else > > list > > end > > > > render :partial => ''search'', :layout => false > > end > > > > I''m showing the get/show in the controller - though I''m not sure if or > > why it would intefere with the search action. > > def show > > @position = Position.find(params[:id]) > > > > respond_to do |format| > > format.html # show.rhtml > > format.xml { render :xml => @position.to_xml } > > end > > end > > > > Stuart > > -- > > http://en.wikipedia.org/wiki/Dark_ambient > > > > > > > > > >-- http://en.wikipedia.org/wiki/Dark_ambient --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 10/3/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 10/3/06, Jason Norris <jasonmnorris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > I was having a problem like this recently. I believe it''s a problem in > > your routing, because params[:search] is returning ''search_position'' > > instead of the value you want. Have a look at the params that are being > > received by your action when you call the URL. > > > > Jason > > > > Not entirely sure what I''m seeing in the log but this is the select > statement going out: > Parameters: {"action"=>"show", "id"=>"search_position", > "controller"=>"positions"} > [4;36;1mUser Columns (0.000000) [0;1mSHOW FIELDS FROM users > [4;35;1mUser Load (0.000000) SELECT * FROM users WHERE > (users.`id` = 11 ) LIMIT 1 > [4;36;1mPosition Columns (0.000000) [0;1mSHOW FIELDS FROM > positions > [4;35;1mPosition Load (0.000000) SELECT * FROM positions > WHERE (positions.id = 0) > > In the def index action I am filtering show by user. I guess at this > point that is just an aside since /positions will return all the records of > that user and I also can remove that condition. Which didn''t help. > What I see here is the odd statement "WHERE (positions.id = 0) > > Not sure how the routing would effect things. Currently my routes.rb are > fairly simple. > > map.resources :users, :sessions, :companies > map.resources :positions, :member => {:description => :get} > > Stuart > > Dark Ambient wrote: > > > There''s an example in the book that presents a search form , listing > > > users and their favorite languages below it. Using the search form > > > text field you can filter the list by their favorite language. > > > > > > I did the demo from the book using the same schema and it works. > > > However, I''m trying to implement this same thing in my app which uses > > > REST controllers, and am running into an error when loading the search > > > > > form. The error is: > > > > > > ActiveRecord::RecordNotFound in PositionsController#show > > > Couldn''t find Position with ID=search_position > > > > > > I''m assuming the issue is in the search action in the controller. The > > > > > list.rhtml should return all the positions. It all looks pretty > > > straight forward. > > > In the controller: > > > > > > def search > > > unless params[:search].blank? > > > @position_pages, @positions = paginate :positions, > > > :per_page => 10, > > > :order => order_from_params, > > > :conditions => Position.conditions_by_like(params[:search]) > > > logger.info < http://logger.info> @positions.size > > > else > > > list > > > end > > > > > > render :partial => ''search'', :layout => false > > > end > > > > > > I''m showing the get/show in the controller - though I''m not sure if or > > > > > why it would intefere with the search action. > > > def show > > > @position = Position.find(params[:id]) > > > > > > respond_to do |format| > > > format.html # show.rhtml > > > format.xml { render :xml => @position.to_xml } > > > end > > > end > > > > > > Stuart > > > -- > > > http://en.wikipedia.org/wiki/Dark_ambient > > > > > > > > >What I''m seeing here ( i think) is that even though it should be accessing the search action in the controllers, it''s calling the get / show action. Hence the problem with the id issue. Anyone ? This might be a routing issue though right now nothing I''ve tried in routes.rb is helping. Stuart --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
I took the whole code and moved it out of my restful controller, since I can''t quite figure out how to make it work in there. However now that it has it''s own controller, I''m getting a nil error. Here is the code: Controller code: class PositionController < ApplicationController def search unless params[:search].blank? @position_pages, @position = paginate(:positions, :per_page => 10, :order => order_from_params, :conditions => Position.conditions(params[:search])) logger.info @positions.size else list end render :partial => ''search'', :layout => false end end The search view <%= start_form_tag(''javascript:void%200'') %> <div class="fake-h1">Listing users <%= text_field_tag ''search'', @search %> <%= observe_field :search, :frequency => 0.5, :update => ''ajaxWrapper'', :complete => "Element.hide(''spinner'')", :before => "Element.show(''spinner'')", :with => "''search='' + encodeURIComponent(value)", :url => {:action=>''search'', :only_path => false} %> </div> <%= end_form_tag %> <div id=''ajaxWrapper''> <%= render :partial=>''search'' %> </div> the _search partial <%= javascript_include_tag :defaults %> <table> <tr> <th>Position</th> <th>Title</th> </tr> <% for position in @positions %> <----- this is where I''m getting the nil object. Makes no sense. <tr> <td><%=h position.company.name %></td> <td><%=h position.title %></td> <td><%= link_to "Show", search_position_path(position) %></td> </tr> <% end %> <%= link_to ''Previous page'', { :page => @position_pages.current.previous } if @position_pages.current.previous %> <%= link_to ''Next page'', { :page => @position_pages.current.next } if @position_pages.current.next %> Stuart On 10/3/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On 10/3/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On 10/3/06, Jason Norris <jasonmnorris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > I was having a problem like this recently. I believe it''s a problem in > > > your routing, because params[:search] is returning ''search_position'' > > > instead of the value you want. Have a look at the params that are > > > being > > > received by your action when you call the URL. > > > > > > Jason > > > > > > > > Not entirely sure what I''m seeing in the log but this is the select > > statement going out: > > Parameters: {"action"=>"show", "id"=>"search_position", > > "controller"=>"positions"} > > [4;36;1mUser Columns (0.000000) [0;1mSHOW FIELDS FROM > > users > > [4;35;1mUser Load (0.000000) SELECT * FROM users WHERE > > (users.`id` = 11 ) LIMIT 1 > > [4;36;1mPosition Columns (0.000000 ) [0;1mSHOW FIELDS FROM > > positions > > [4;35;1mPosition Load (0.000000) SELECT * FROM positions > > WHERE (positions.id = 0) > > > > In the def index action I am filtering show by user. I guess at this > > point that is just an aside since /positions will return all the records of > > that user and I also can remove that condition. Which didn''t help. > > What I see here is the odd statement "WHERE (positions.id = 0) > > > > Not sure how the routing would effect things. Currently my routes.rbare fairly simple. > > > > map.resources :users, :sessions, :companies > > map.resources :positions, :member => {:description => :get} > > > > Stuart > > > > Dark Ambient wrote: > > > > There''s an example in the book that presents a search form , listing > > > > users and their favorite languages below it. Using the search form > > > > text field you can filter the list by their favorite language. > > > > > > > > I did the demo from the book using the same schema and it works. > > > > However, I''m trying to implement this same thing in my app which > > > uses > > > > REST controllers, and am running into an error when loading the > > > search > > > > form. The error is: > > > > > > > > ActiveRecord::RecordNotFound in PositionsController#show > > > > Couldn''t find Position with ID=search_position > > > > > > > > I''m assuming the issue is in the search action in the > > > controller. The > > > > list.rhtml should return all the positions. It all looks pretty > > > > straight forward. > > > > In the controller: > > > > > > > > def search > > > > unless params[:search].blank? > > > > @position_pages, @positions = paginate :positions, > > > > :per_page => 10, > > > > :order => order_from_params, > > > > :conditions => Position.conditions_by_like(params[:search]) > > > > logger.info < http://logger.info> @positions.size > > > > else > > > > list > > > > end > > > > > > > > render :partial => ''search'', :layout => false > > > > end > > > > > > > > I''m showing the get/show in the controller - though I''m not sure if > > > or > > > > why it would intefere with the search action. > > > > def show > > > > @position = Position.find(params[:id]) > > > > > > > > respond_to do |format| > > > > format.html # show.rhtml > > > > format.xml { render :xml => @position.to_xml } > > > > end > > > > end > > > > > > > > Stuart > > > > -- > > > > http://en.wikipedia.org/wiki/Dark_ambient > > > > > > > > > > > > > > What I''m seeing here ( i think) is that even though it should be accessing > the search action in the controllers, it''s calling the get / show action. > Hence the problem with the id issue. > Anyone ? > This might be a routing issue though right now nothing I''ve tried in > routes.rb is helping. > > Stuart > >-- http://en.wikipedia.org/wiki/Dark_ambient --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---