[Rails] Re: Doing Subselect query in Rails... Syntax problem

2008-12-10 Thread Jay Mark
Jay Mark wrote: > Priya Buvan wrote: >> @books = Book.find(:all, :joins=>"books inner join authors as a on >> books.title=a.name", :conditions => ['name LIKE ? ', >> '%'+params[:author][:name]+'%']) >> >> >>

[Rails] Re: wrong number of arguments (0 for 1) error.... Help!!!

2008-12-10 Thread Jay Mark
Frederick Cheung wrote: > On Dec 10, 5:36�am, Jay Mark <[EMAIL PROTECTED]> wrote: >> Rails? >> Is subselect not supported in Rails? >> > > For the sake of argument you can do > > @books = Books.find_by_sql ["SELECT * FROM books WHERE title

[Rails] Re: Doing Subselect query in Rails... Syntax problem

2008-12-10 Thread Jay Mark
Priya Buvan wrote: > @books = Book.find(:all, :joins=>"books inner join authors as a on > books.title=a.name", :conditions => ['name LIKE ? ', > '%'+params[:author][:name]+'%']) > > > try with the above code I put the code in Authors Controller as it is, and I get nil object error. Since I

[Rails] Re: wrong number of arguments (0 for 1) error.... Help!!!

2008-12-09 Thread Jay Mark
Ryan Bigg wrote: > I have no clue. Author.find_by_name should be working when it > (apparently) is not. Something is broken. > - > Ryan Bigg > Freelancer > http://frozenplague.net I think so too. Thanks for your help. Why is it so hard to find the correct syntax for doing a subselect in Rail

[Rails] Re: wrong number of arguments (0 for 1) error.... Help!!!

2008-12-09 Thread Jay Mark
Ryan Bigg wrote: > And finally, what version of Rails? > - > Ryan Bigg > Freelancer > http://frozenplague.net I am using 2.0.2 with mysql database Cypray -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you ar

[Rails] Re: Doing Subselect query in Rails... Syntax problem

2008-12-09 Thread Jay Mark
Jeff Cohen wrote: > On Dec 9, 1:47�pm, Jay Mark <[EMAIL PROTECTED]> wrote: >> Jeff Cohen wrote: >> Thanks for all your help Jeff. >> It is still not working. >> The find_by_name, gives me this error: >> "undefined method `find_by_name' for

[Rails] Re: Doing Subselect query in Rails... Syntax problem

2008-12-09 Thread Jay Mark
Jeff Cohen wrote: > On Dec 9, 11:52�am, Jay Mark <[EMAIL PROTECTED]> wrote: > >> where title is equal to the title returned by the inner query. >> The strange thing here is, title has a unique entry in authors table, >> but title has duplicate entries in the book t

[Rails] Re: Doing Subselect query in Rails... Syntax problem

2008-12-09 Thread Jay Mark
Jeff Cohen wrote: > On Dec 9, 11:06�am, Jay Mark <[EMAIL PROTECTED]> wrote: >> @books = Books.find_by_sql ["SELECT * FROM books WHERE title IN SELECT >> title FROM authors WHERE name = ?", params[:author][:name]] >> >> One problem is where to put the (

[Rails] Doing Subselect query in Rails... Syntax problem

2008-12-09 Thread Jay Mark
I have to use subselect for this query. find_all_by_name and joins will not work. Please I need help with getting the correct syntax for doing subselect the rails way. The query works fine in mysql. I can't find the syntax in the docs or may be I was looking in the wrong place. My project is due t

[Rails] Re: wrong number of arguments (0 for 1) error.... Help!!!

2008-12-09 Thread Jay Mark
Here is the result from ruby script/console >> Author.new => # >> Book.new => # Ryan Bigg wrote: > Ok... then you're on your own if you don't know how to type "ruby > script/console" into a command prompt window and then type some more > stuff > - > Ryan Bigg > Freelancer > http://frozen

[Rails] Re: wrong number of arguments (0 for 1) error.... Help!!!

2008-12-08 Thread Jay Mark
I am using InstantRails. All I have is the command The "Open Ruby Console Window" gives me the command window Ryan Bigg wrote: > I meant doing it in ruby script/console, not just in the command > - > Ryan Bigg > Freelancer > http://frozenplague.net -- Posted via http://www.ruby-forum.com/

[Rails] Re: wrong number of arguments (0 for 1) error.... Help!!!

2008-12-08 Thread Jay Mark
It says: Author.new is not recognized as an internal or external command, operable program or batch file. same for Book. Ryan Bigg wrote: > And in the console do Author.new and Book.new and show me the output > of each please. > - > Ryan Bigg > Freelancer > http://frozenplague.net -- Po

[Rails] Re: wrong number of arguments (0 for 1) error.... Help!!!

2008-12-08 Thread Jay Mark
Here are my models: class Author < ActiveRecord::Base belongs_to :book end class Book < ActiveRecord::Base has_many :authors end Ryan Bigg wrote: > pastie your models please > - > Ryan Bigg > Freelancer > http://frozenplague.net -- Posted via http://www.ruby-forum.com/. -

[Rails] Re: wrong number of arguments (0 for 1) error.... Help!!!

2008-12-08 Thread Jay Mark
I am using find_by_sql because I get this error when I use find_by_name or find_all_by_name "undefined method `find_by_name' for # Stop using find_by_sql! > > You can just do: > > author = Author.find_by_name(params[:author][:name]) > books = author.books.find(:all, :select => "title") -- Po

[Rails] Re: wrong number of arguments (0 for 1) error.... Help!!!

2008-12-08 Thread Jay Mark
Thanks guys, the first query is working fine now. Rails is still rejecting the syntax of this subselect: @books = Books.find_by_sql ["SELECT * FROM books WHERE title IN SELECT title FROM authors WHERE name = ?", params[:author][:name]] I know the inner select should be in (), but its not takin

[Rails] Re: wrong number of arguments (0 for 1) error.... Help!!!

2008-12-08 Thread Jay Mark
an't find it in the Docs. Please send me any pointers. Thanks Cypray Frederick Cheung wrote: > On Dec 8, 7:31�pm, Jay Mark <[EMAIL PROTECTED]> wrote: >> Thanks for your help Fred. The wrong number of argument problem is gone. >> >> The queries are still not workin

[Rails] Re: wrong number of arguments (0 for 1) error.... Help!!!

2008-12-08 Thread Jay Mark
ROM authors where name = ?", 'name')] It is not accepting '(' or '[' to enclose the inner SELECT I have tested this also in mysql and it works fine. Does any one know the correct syntax for a subselect in Rails? Thanks Cypray. Frederick Cheung wrote: > On

[Rails] wrong number of arguments (0 for 1) error.... Help!!!

2008-12-08 Thread Jay Mark
I am using Rails 2.0.2 with mysql database I am getting this error when running a query with Find_by_sql: "wrong number of arguments (0 for 1)" Here are my queries: @authors = Author.find_by_sql["SELECT * FROM authors WHERE name = ?', name"] Also @books = Books.find_by_sql["SELECT * FROM books

[Rails] nil object problem in Rails 2.0.2

2008-12-06 Thread Jay Mark
I think my problem is that Rails is not seeing the private method "def author_age" that is holding the result of the query. Do I suppose to put this in the Controller and not in the model? How does the object @results get known to Rails? Here is my code: class Author < ActiveRecord::Base has_

[Rails] Re: Changing primary.. Rails/mysql

2008-12-05 Thread Jay Mark
Well, I am having trouble with this query: class Author < ActiveRecord::Base has_many :books def author_age @results = Author.find :all, :conditions => ["age = ?", params[:authors]] end end I have this on view\authors\show.html Author Name Age <% @results.each do |result|

[Rails] Changing primary.. Rails/mysql

2008-12-05 Thread Jay Mark
I am using Rails 2.0.2 with mysql database Migrate sets the primary key to id. Is it possible to change it to another column? If yes, how? Thanks for your help Cypray. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message becau

[Rails] Re: Help with ruby query!

2008-12-04 Thread Jay Mark
The problem could be the query because when I search for one record, it works. So, this works fine without the query and the loop. Author Name Age <%=h @author.name %> <%=h @author.age %> <% end %> But this returns one 'Name' for the selected 'age'. That means it is returning the

[Rails] Re: Help with ruby query!

2008-12-04 Thread Jay Mark
I made those changes, but I am still getting this error: "You have a nil object when you didn't expect it!" It is pointing to the line with the loop: <% @results.each do |result| My model look like this: class Author < ActiveRecord::Base has_many :books def author_age @results = Author.f

[Rails] Re: Help with ruby query!

2008-12-04 Thread Jay Mark
not sure if this is right! <%=h @result.name %> <%=h @result.age %> What I want to do is to display the 'name' and 'age' that the query returned. Please help! Cypray Frederick Cheung wrote: > On 4 Dec 2008, at 14:28, Jay Mark wrote: >>

[Rails] Re: Help with ruby query!

2008-12-04 Thread Jay Mark
Thanks for the info guys. Now I am getting this error coming from the author's model: "syntax error, unexpected tASSOC, expecting ')'" This is what I have in author's class class Author < ActiveRecord::Base has_many :books def author_age Author.find :all, (:conditions => ["age = ?", p

[Rails] Help with ruby query!

2008-12-03 Thread Jay Mark
I am using Rails 2.0.2 with mysql database I have two tables: book and author Table book has 3 columns: id, isbn, and title Table author has 3 columns: id, name, and age In the models I have: class Book < ActiveRecord::Base belongs_to :author end class Author < ActiveRecord::Base has_many :b

[Rails] Re: New to Rails... Help!

2008-12-02 Thread Jay Mark
Sazima, You are so right Sazima. I am confused like a beginner. Thanks for clearing that up for me. I have started learning Ruby. Thanks for all the suggestions guys. Jay. Sazima wrote: > Jay, > > You're confusing Rails with InstantRails. Rails is the web framework, > Instant Rails is a pa

[Rails] Re: New to Rails... Help!

2008-12-01 Thread Jay Mark
William, thanks for your help in resolving this issue. It works great now. Thanks a lot. Please, if you know any good book or online material on Ruby/InstantRails 2.0.2, please post it in the Forum. Thanks Cypray wfisk wrote: > class Country > > > def people_tribes > peopl

[Rails] New to Rails... Help!

2008-12-01 Thread Jay Mark
I am new to Ruby/InstantRails. I am using InstantRails 2.0.2 with mysql database My application is named Area, it has two tables: people and country Table people has two columns: name and tribe Table country has two columns: location and population In the models I have: class People < ActiveReco