Sorry I can''t access IRC from work so I hope you don''t mind me asking my newbie questions here: 1) I have the following code: @post = Post.find(@params[''id'']) @comments = Comment.find_all "post_id = #@params[''id'']", "created_on ASC" And I am have problems with the second line. I want to pass the id from my post to the comments line to get the comments for that post. What am I doing wrong? I tried a ton of different ways and they all don''t work 2) Does Routes work with Apache because I am running into some problems. I added the following line to my routes.rb file: map.connect ''/'', :controller => ''post'', :action => ''index'' And when I go to the root of my project I get the default startup page for a new rails application... the index.html file. What am I doing wrong? 3) Instead of destroying an entry I want to update the deleted field I have to equal 1. Should I use the update or update_all methods and does anyone have examples of them being used :-). Thanks for your guys help. I know they are mundane questions. But I am only on my third day of rails... and OO languages come to think of it. :-)
1) Try changing "post_id = #@params[''id'']" to "post_id = #{@params[''id'']}" 2) Move that index.html out of that dir. 3) @post = Post.find.... @post.deleted = 1 @post.save Little terse, but HTH -w On Thu, 10 Mar 2005 10:41:00 -0500, John Baku <john-CC0oh5EnFfVBDgjK7y7TUQ@public.gmane.org> wrote:> Sorry I can''t access IRC from work so I hope you don''t mind me asking my newbie > questions here: > > 1) I have the following code: > > @post = Post.find(@params[''id'']) > @comments = Comment.find_all "post_id = #@params[''id'']", "created_on ASC" > > And I am have problems with the second line. I want to pass the id from my post > to the comments line to get the comments for that post. What am I doing wrong? > I tried a ton of different ways and they all don''t work > > 2) Does Routes work with Apache because I am running into some problems. I > added the following line to my routes.rb file: > > map.connect ''/'', :controller => ''post'', :action => ''index'' > > And when I go to the root of my project I get the default startup page for a new > rails application... the index.html file. > > What am I doing wrong? > > 3) Instead of destroying an entry I want to update the deleted field I have to > equal 1. Should I use the update or update_all methods and does anyone have > examples of them being used :-). > > Thanks for your guys help. I know they are mundane questions. But I am only on > my third day of rails... and OO languages come to think of it. :-) > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Will Schenk http://www.sublimeguile.com http://www.myelinate.com
John Baku wrote:>Sorry I can''t access IRC from work so I hope you don''t mind me asking my newbie >questions here: > >1) I have the following code: > >@post = Post.find(@params[''id'']) >@comments = Comment.find_all "post_id = #@params[''id'']", "created_on ASC" > >And I am have problems with the second line. I want to pass the id from my post >to the comments line to get the comments for that post. What am I doing wrong? >I tried a ton of different ways and they all don''t work > >2) Does Routes work with Apache because I am running into some problems. I >added the following line to my routes.rb file: > >map.connect ''/'', :controller => ''post'', :action => ''index'' > >And when I go to the root of my project I get the default startup page for a new >rails application... the index.html file. > >What am I doing wrong? > >3) Instead of destroying an entry I want to update the deleted field I have to >equal 1. Should I use the update or update_all methods and does anyone have >examples of them being used :-). > >Thanks for your guys help. I know they are mundane questions. But I am only on >my third day of rails... and OO languages come to think of it. :-) >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > >Is the second statment really needed? In some of my view i loop directly from the "master" object. Like: <ul>. <% for each comment in @user.comments %> <li><%= comment.body %> <% end %> You need to have the correct models defined, but then activerecord does the magic stuff for you. models/post.rb has_many :comments models/comment.rb belongs_to :post Regards // JoNtE
Jonas Montonen wrote:> John Baku wrote: > >> Sorry I can''t access IRC from work so I hope you don''t mind me asking >> my newbie >> questions here: >> >> 1) I have the following code: >> >> @post = Post.find(@params[''id'']) >> @comments = Comment.find_all "post_id = #@params[''id'']", "created_on >> ASC" >> >> And I am have problems with the second line. I want to pass the id >> from my post >> to the comments line to get the comments for that post. What am I >> doing wrong? I tried a ton of different ways and they all don''t work >> >> 2) Does Routes work with Apache because I am running into some >> problems. I >> added the following line to my routes.rb file: >> >> map.connect ''/'', :controller => ''post'', :action => ''index'' >> >> And when I go to the root of my project I get the default startup >> page for a new >> rails application... the index.html file. >> >> What am I doing wrong? >> >> 3) Instead of destroying an entry I want to update the deleted field >> I have to >> equal 1. Should I use the update or update_all methods and does >> anyone have >> examples of them being used :-). >> >> Thanks for your guys help. I know they are mundane questions. But I >> am only on >> my third day of rails... and OO languages come to think of it. :-) >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> > Is the second statment really needed? > In some of my view i loop directly from the "master" object. > Like: > <ul>. > <% for each comment in @user.comments %> > <li><%= comment.body %> > <% end %> > > You need to have the correct models defined, but then activerecord > does the magic stuff for you. > > models/post.rb > has_many :comments > > models/comment.rb > belongs_to :post > > Regards > // JoNtE > > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >Sorry, typo.... <ul>. <% for each comment in @post.comments %> <li><%= comment.body %> <% end %>
On Thursday 10 March 2005 10:41, John Baku wrote:> 1) I have the following code: > > @post = Post.find(@params[''id'']) > @comments = Comment.find_all "post_id = #@params[''id'']", "created_on ASC"@comments = Comment.find_all(["post_id = ?", @params[''id'']], "created_on ASC") This guards against sql injection as well.> map.connect ''/'', :controller => ''post'', :action => ''index'' > > And when I go to the root of my project I get the default startup page for > a new rails application... the index.html file.Delete the file public/index.html. -- Nicholas Seckar aka. Ulysses
> Delete the file public/index.html.Just curious: why? Is it checking for the existence of public/index.html before even trying the correct route? -- rick http://techno-weenie.net
Thanks everyone for your great help!!!! Saved me a lot of time. Quoting Will Schenk <wschenk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> 1) Try changing > "post_id = #@params[''id'']" to > "post_id = #{@params[''id'']}" > > 2) Move that index.html out of that dir. > > 3) > @post = Post.find.... > @post.deleted = 1 > @post.save > > Little terse, but HTH > > -w > > On Thu, 10 Mar 2005 10:41:00 -0500, John Baku <john-CC0oh5EnFfVBDgjK7y7TUQ@public.gmane.org> wrote: > > Sorry I can''t access IRC from work so I hope you don''t mind me asking my > newbie > > questions here: > > > > 1) I have the following code: > > > > @post = Post.find(@params[''id'']) > > @comments = Comment.find_all "post_id = #@params[''id'']", "created_on ASC" > > > > And I am have problems with the second line. I want to pass the id from my > post > > to the comments line to get the comments for that post. What am I doing > wrong? > > I tried a ton of different ways and they all don''t work > > > > 2) Does Routes work with Apache because I am running into some problems. I > > added the following line to my routes.rb file: > > > > map.connect ''/'', :controller => ''post'', :action => ''index'' > > > > And when I go to the root of my project I get the default startup page for > a new > > rails application... the index.html file. > > > > What am I doing wrong? > > > > 3) Instead of destroying an entry I want to update the deleted field I have > to > > equal 1. Should I use the update or update_all methods and does anyone > have > > examples of them being used :-). > > > > Thanks for your guys help. I know they are mundane questions. But I am > only on > > my third day of rails... and OO languages come to think of it. :-) > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > -- > Will Schenk > http://www.sublimeguile.com > http://www.myelinate.com > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Nicholas Seckar wrote:> On Thursday 10 March 2005 10:41, John Baku wrote: >>@post = Post.find(@params[''id'']) >>@comments = Comment.find_all "post_id = #@params[''id'']", "created_on ASC" > > @comments = Comment.find_all(["post_id = ?", @params[''id'']], "created_on ASC") > This guards against sql injection as well.Not sure whether this was mentioned: class Post < ActiveRecord::Base has_many :comments, :order => ''created_on ASC'' end post = Post.find(@params[''id'']) post.comments http://rails.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html jeremy
By doing this I always have the comments ordered without me having to specify it? Quoting Jeremy Kemper <jeremy-w7CzD/W5Ocjk1uMJSBkQmQ@public.gmane.org>:> Nicholas Seckar wrote: > > On Thursday 10 March 2005 10:41, John Baku wrote: > >>@post = Post.find(@params[''id'']) > >>@comments = Comment.find_all "post_id = #@params[''id'']", "created_on ASC" > > > > @comments = Comment.find_all(["post_id = ?", @params[''id'']], "created_on > ASC") > > This guards against sql injection as well. > > Not sure whether this was mentioned: > > class Post < ActiveRecord::Base > has_many :comments, :order => ''created_on ASC'' > end > > post = Post.find(@params[''id'']) > post.comments > >http://rails.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html> > jeremy > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On 10.3.2005, at 19:16, John Baku wrote:> By doing this I always have the comments ordered without me having to > specify > it?Oh yeah, baby. Gotta love Rails, huh? //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Yes. Check the rewrite rules inside .htacess. On Thu, 10 Mar 2005 10:01:25 -0600, Rick Olson <technoweenie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Delete the file public/index.html. > > Just curious: why? Is it checking for the existence of > public/index.html before even trying the correct route? > > -- > rick > http://techno-weenie.net > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Will Schenk http://www.sublimeguile.com http://www.myelinate.com