Hi Priya ,
thanks for your suggestions.
Finally i am able to do the search with tagname.
presently i can search the database by typing the string in the search box.
But now i want to provide a dropdown box of search parameters instead of typing.
here my search application is usin ajax .
can you give any suggestions to create dropdown box and once i select
the option from dropdown box how to link with it for search function?
take a look at my search code:
-----------------------------------------
in index.html.erb
-------------------------------------------------
Search: <input type="string" id="search_form" name="search" />
<img id="spinner" src="/images/indicator.gif" style="display: none;" />
<div id="results"></div>
<%= observe_field 'search_form',
:frequency => 0.5,
:update => 'results',
:url => { :controller => 'streams', :action=> 'get_results' },
:with => "'search_text=' + escape(value)",
:loading => "document.getElementById('spinner').style.display='inline'",
:loaded => "document.getElementById('spinner').style.display='none'" %>
-------------------------------------------------------------------------------
the search mthod defined in controller is
--------------------------------------------
def get_results
if request.xhr?
if params['search_text'].strip.length > 0
terms = params['search_text'].split.collect do |word|
"%#{word.downcase}%"
end
if blank?
flash[:notice] = 'Stream was successfully updated.'
else
@streams = Stream.find_tagged_with(params[:search_text])
end
end
render :partial => "search"
else
redirect_to :action => "index"
end
end
thnaks for any suggetions and help
regards
Srikanth.
On Thu, Dec 11, 2008 at 11:20 AM, sreekanth. G <[email protected]> wrote:
> Hi Priya,
>
> below are the details of tables and corresponding taggings between
> streams and tags tables in taggings table.
> mysql> select * from streams;
> +----+------------+-----------------------------------+------------+---------+-----------+-----------+------------+------------+
> | id | name | location | resolution |
> bitrate | framerate | codecname | created_on | updated_on |
> +----+------------+-----------------------------------+------------+---------+-----------+-----------+------------+------------+
> | 1 | dust.mpeg2 | E:\streams\RED_S_J_JE_In_NT.divx | 1920x1080 |
> 6mbps | 30fps | mpeg2 | 2008-12-08 | 2008-12-08 |
> | 2 | mummy.264 | E:\streams\RED_S_J_JE_In_NT.divx | 720x480 |
> 4mbps | 30fps | h264 | 2008-12-08 | 2008-12-08 |
> | 3 | hiphop.aac | na | na |
> na | na | aac | 2008-12-10 | 2008-12-10 |
> | 5 | jazz.aac | na | na |
> na | na | aac | 2008-12-10 | 2008-12-10 |
> +----+------------+-----------------------------------+------------+---------+-----------+-----------+------------+------------+
> 4 rows in set (0.03 sec)
>
> mysql> select * from tags;
> +----+--------------+
> | id | name |
> +----+--------------+
> | 1 | mpeg2 |
> | 2 | h264 720x480 |
> | 3 | aac |
> +----+--------------+
> 3 rows in set (0.00 sec)
>
> mysql> select * from taggings;
> +----+--------+-------------+---------------+
> | id | tag_id | taggable_id | taggable_type |
> +----+--------+-------------+---------------+
> | 1 | 1 | 1 | Stream |
> | 2 | 2 | 2 | Stream |
> | 3 | 3 | 3 | Stream |
> | 4 | 3 | 5 | Stream |
> +----+--------+-------------+---------------+
> 4 rows in set (0.00 sec)
>
> can i use the query to search with tag field like:
>
> @streams = Stream.find(:all, :joins => "streams inner join tags as t on
> stream.id=t.id", :conditions => ['name LIKE ?',
> '%'+params[:search_text]+'%'],:select => "name")
>
> from the above query what i understand is:
> it joing streams and tags table but using the "name" column of tags
> table it is finding and storing the result of stream names from
> streams table in @streams array.
>
> if i a m wrong let me know ?
> do i need to mention anywhere association between tables in the
> corresponding models?
>
> is there any procedure to make it work ?
>
>
> thanks
> srikanth
>
>
>
>
>
>
> On Thu, Dec 11, 2008 at 10:46 AM, Priya Buvan
> <[email protected]> wrote:
>>
>> If you want to search with streams field, then you have to pass all
>> those parameters else its enough to pass tag field name alone.
>>
>> Also we can join the 2 tables so no need to give like
>> @streams=Stream.fine(:all) for tag.
>>
>> Do you have column heading as "name" in tag table? Check it and give the
>> correct attribute name in the place of "name"
>> --
>> Posted via http://www.ruby-forum.com/.
>>
>> >>
>>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---