Hi Daniel,

actually i have Stream model and in the controller i added  like:

def search
>     search_criteria = Stream.find_tagged_with(params[:search])
>      if search_criteria.empty?
>        flash[:notice] = "Please enter search criteria"
>        @searchresults = ""
>      else
>        @searchresults = Streams.find
> (:all, :conditions=>search_critera)

2)but did you add ':collection'
"map.resources :streams" after setting up this resource?
i am not clear this qustion.
just adde the map.resources :streams, :collection => {:search=>:get}
in route.rb


3) hw can i write an action to display the search result instead of show action?


thanks



On Sat, Dec 6, 2008 at 12:48 PM, Daniel Bush <[EMAIL PROTECTED]> wrote:
>
>
> Hi,
> I think you have several issues...
>
> srikanth wrote:
>
>> hi,
>>
>> i am implementing a search box from index page,search box allow s the
>> tag name to be searched and it should display the results on the other
>> page.
>>
>> if enter a tag name in search box once i press the search button i am
>> getting error like:
>>
>>
>> ActiveRecord::RecordNotFound in StreamsController#show
>> Couldn't find Stream with ID=search
>> RAILS_ROOT: E:/srikanth/InstantRails-2.0-win/rails_apps/stdb
>> Application Trace | Framework Trace | Full Trace
>> E:/srikanth/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/
>> activerecord-2.0.2/lib/active_record/base.rb:1267:in `find_one'
>> E:/srikanth/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/
>> activerecord-2.0.2/lib/active_record/base.rb:1250:in `find_from_ids'
>> E:/srikanth/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/
>> activerecord-2.0.2/lib/active_record/base.rb:504:in `find'
>> app/controllers/streams_controller.rb:16:in `show'
>
> This appears to be a 'show' action - not 'search'.
> I'd say that your GET-request for /streams/search?search=... is being
> mapped to your 'show' action - see last comment below.
>
>>
>> corresonding url have like:
>> http://localhost:3000/streams/search?search=352x240
>>
>> so can any one help me out in this issue.
>>
>> 1)in controller added search method like:
>>
>> ####added for search option
>>   def search
>>     search_criteria = Article.find_tagged_with(params[:search])
>>      if search_criteria.empty?
>>        flash[:notice] = "Please enter search criteria"
>>        @searchresults = ""
>>      else
>>        @searchresults = Streams.find
>> (:all, :conditions=>search_critera)
>
> Even though the error was in 'show', there look to be some errors here
> in 'search'.
>
> I think Article.find_tagged_with will return an array of Article
> models.  You haven't mentioned your Article model - you seem to have a
> Stream model (which you should use in the singular not plural).  So
> maybe you mean Stream.  You then use this for the :conditions clause
> in Streams.find(...) which is probably not going to work
> because :conditions corresponds to a WHERE-clause in sql.  Check the
> docs for the 'find' method (api.rubyonrails.org).
>
>>      end
>>        respond_to do |format|
>>        format.html # show.html.erb
>>        format.xml  { render :xml => @stream }
>>      end
>>   end
>> ################
>>
>> 2)and in view/streams/index.html.erb file
>>
>> <% form_tag(search_streams_path(), :method => :get) do %>
>>  <%= label(:search, :tag, "Search:") %><br />
>>  <input name="search" id="tag" type="text" size="17" value='<%=
>> session[:search_keys] %>' style="width:123px;" />
>>  <input type="image" id="bt_zoek" src="/images/search.jpg"
>> alt="search" style="border:none;"/>
>> <% end %>
>>
>> 3)in routes.rb added line;
>>
>>   map.resources :streams, :collection => {:search=>:get}
>
> Just a guess: but did you add ':collection' to
> "map.resources :streams" after setting up this resource? If you did
> and you didn't reload the routing table (restart you app), then the
> search action won't take effect and your show action might be used
> instead which might be why you get the error in 'show' with id being
> mapped to 'search'.
>
>>
>>
>
> HTH
>
> --
> Daniel Bush
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to