I am newbie in Ruby. please help me immediately. I have a input field in
my index page for search a movie by entering the ID of the movie.
the html part of search...
<%= start_form_tag :action => ''search'' %>
<label for="id">ID</label>
<%= text_field "movie", "id" %>
<%= submit_tag "Search" %>
<%= end_form_tag %>
in controller
def search
query = "select *
from movies
where id = ?
"
@report = Movie.find_by_sql([query, params[:id]])
end
But it return nothings.
NUll value in params[:id]
How can pass the input value in the find_by_sql() function?
Please please help me immediately.
Thanks in advanced.
Amin
--
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
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?hl=en
-~----------~----~----~----~------~----~------~--~---
Thorsten
2007-Feb-20 11:23 UTC
Re: How can pass the input value in the find_by_sql() function?
1) "please help me immediately" is rude. You think people say "oh i know the answer but i will wait with the answer for 3 days?" People will help if they can. 2) <%= text_field "movie", "id" %> will compile to: <input type="text" id="movie_id" name="movie[id]" value="<%= @movie.id %>" /> (look at your generated HTML) so your parameter is params[:movie][:id] and NOT params[:id] => @report = Movie.find_by_sql([query, params[:movie][:id]]) 3) why don''t you just use: @report = Movie.find(params[:movie][:id]) that will have the same result, plus it gives you the advantages of AR collections, which find_by_sql doesn''t On 20 Feb., 12:04, Tuhin <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I am newbie in Ruby. please help me immediately. I have a input field in > my index page for search a movie by entering the ID of the movie. > > the html part of search... > > <%= start_form_tag :action => ''search'' %> > <label for="id">ID</label> > <%= text_field "movie", "id" %> > <%= submit_tag "Search" %> > <%= end_form_tag %> > > in controller > > def search > query = "select * > from movies > where id = ? > " > @report = Movie.find_by_sql([query, params[:id]]) > > end > > But it return nothings. > > NUll value in params[:id] > > How can pass the input value in the find_by_sql() function? > Please please help me immediately. > > Thanks in advanced. > > Amin > > -- > Posted viahttp://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 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?hl=en -~----------~----~----~----~------~----~------~--~---
Ruhul Amin
2007-Feb-20 11:31 UTC
Re: How can pass the input value in the find_by_sql() functi
Thorsten wrote:> 1) "please help me immediately" is rude. You think people say "oh i > know the answer but i will wait with the answer for 3 days?" People > will help if they can. > > 2) <%= text_field "movie", "id" %> > will compile to: > <input type="text" id="movie_id" name="movie[id]" value="<%= @movie.id > %>" /> > (look at your generated HTML) > so your parameter is params[:movie][:id] and NOT params[:id] > > => @report = Movie.find_by_sql([query, params[:movie][:id]]) > > 3) why don''t you just use: > > @report = Movie.find(params[:movie][:id]) > > that will have the same result, plus it gives you the advantages of AR > collections, which find_by_sql doesn''tDear Thorsten, Thx for ur help. But I do not have @movie.id value. I just take a input for the movie id and search the id in the "movies" table so i can not use it. I also try to use Movie.find(params[:id]) but error return as id is null. please try to understand my question. -- 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 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?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten
2007-Feb-20 11:40 UTC
Re: How can pass the input value in the find_by_sql() functi
1) as i already said, it is not params[:id], it''s params[:movie][:id]
so, as i already said, try Movie.find(params[:movie][:id])
2) you don''t need the @movie.id value. if it''s not there, it
won''t be
filled in the text_field, but that''s fine. it''s just part of
how the
FormTagHelpers build the Tags.
look at your generated HTML
On 20 Feb., 12:31, Ruhul Amin
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> Thorsten wrote:
> > 1) "please help me immediately" is rude. You think people
say "oh i
> > know the answer but i will wait with the answer for 3 days?"
People
> > will help if they can.
>
> > 2) <%= text_field "movie", "id" %>
> > will compile to:
> > <input type="text" id="movie_id"
name="movie[id]" value="<%= @movie.id
> > %>" />
> > (look at your generated HTML)
> > so your parameter is params[:movie][:id] and NOT params[:id]
>
> > => @report = Movie.find_by_sql([query, params[:movie][:id]])
>
> > 3) why don''t you just use:
>
> > @report = Movie.find(params[:movie][:id])
>
> > that will have the same result, plus it gives you the advantages of AR
> > collections, which find_by_sql doesn''t
>
> Dear Thorsten,
> Thx for ur help. But I do not have @movie.id value.
> I just take a input for the movie id and search the id in the
"movies"
> table
> so i can not use it.
> I also try to use Movie.find(params[:id]) but error return as id is
> null.
> please try to understand my question.
>
> --
> Posted viahttp://www.ruby-forum.com/.- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---
Ruhul Amin
2007-Feb-20 11:44 UTC
Re: How can pass the input value in the find_by_sql() functi
thx, Thorsten. It works fine. Amin -- 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 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?hl=en -~----------~----~----~----~------~----~------~--~---
Ruhul Amin
2007-Feb-20 12:00 UTC
Re: How can pass the input value in the find_by_sql() functi
Sorry for that.
My main missionis to search a movie by its name. so please tell me
how can i use to write the sql query using "like"
suppose i want to search all movie whose name begin with "mission"
select *from movies where name like ''mission%''
so what will be the following two lines?
query = "select * from movies where name like ?
"
@report = Movie.find_by_sql([query, params[:movie][:id]])
Thanks in advanced
Amin
--
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
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?hl=en
-~----------~----~----~----~------~----~------~--~---
Ruhul Amin wrote:> My main missionis to search a movie by its name. so please tell me > how can i use to write the sql query using "like"The books /Agile Development with Rails/ and /Rails Recipes/ cover that. Please consider getting one, or both. They will teach this trick: raise params.inspect Write that into an action, and it will show you what parameters the view sends to the action. Then take it out!> suppose i want to search all movie whose name begin with "mission"@reports = Movie.find(:all, :conditions => [''name like ?'', "%mission%"]) Now replace mission with a variable, such as "%#{search_term}%". -- Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!! --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---