John Baku
2005-Mar-10 18:41 UTC
error messages, loops and saves, actionmailer and finaly authentication
Thanks to everyone who responded to my first set of questions. Not only did I get my questions answered but I improved my code and learned a couple new things. I think I prefer the mailing list over IRC... easier to follow :-) I have some more questions if you don''t mind. Some are Rails related and some are Ruby related. 1) This is concerning displaying error messages. I am assuming I should use error_messages_for "objectName". So there are a couple questions that go with this. a) If there is no errors being passed to the action then I get an error. How do I check to see if an error is being passed and if so show error_messages_for? b) From what I understood while playing around if I use a render_action the error message will be passed but if I do a redirect_to the errors are not passed. How can I use a render_action when the action I want to render if I get an error is in another controller? 2) This is a continuation from a question from before. Instead of deleting a record I mark it as deleted. If I mark a post as deleted I also want to mark the comments associated with it as deleted. I tried the following and it did not work: @comments = Comment.find_all "post_id = 1" @comments.each do |comment| comment.deleted = 1 comment.save end It did not work. Am I doing it the wrong way? 3) After a comment is posted I want to get emailed. Anyone know of a good tutorial/anything to help explain to me how to use actionmailer in lamins terms? :-) 4) Some of the actions I want the user to have to authenticate himself before he/she can execute them. Any easy Rails way of doing it? I was thinking of just passing a username and password in the URL and verifying it for each action that needs validation. Thanks again for all your help guys :-). Your Friend, John
Nathan Wright
2005-Mar-10 18:53 UTC
Re: error messages, loops and saves, actionmailer and finaly authentication
> 3) After a comment is posted I want to get emailed. Anyone know of a > good > tutorial/anything to help explain to me how to use actionmailer in lamins > terms? :-)I''m still trying to get this to work myself (so take my recommendation with a grain of salt) but have a look at <URL: http://wiki.rubyonrails.com/rails/show/HowToSendEmailsWithActionMailer > -- Nathan Wright http://www.brandalism.com
Jarkko Laine
2005-Mar-10 19:15 UTC
Re: error messages, loops and saves, actionmailer and finaly authentication
On 10.3.2005, at 20:41, John Baku wrote:> Thanks to everyone who responded to my first set of questions. Not > only did I > get my questions answered but I improved my code and learned a couple > new > things. > > I think I prefer the mailing list over IRC... easier to follow :-) > > I have some more questions if you don''t mind. Some are Rails related > and some > are Ruby related. > > 1) This is concerning displaying error messages. I am assuming I > should use > error_messages_for "objectName". So there are a couple questions that > go with > this. > > a) If there is no errors being passed to the action then I get an > error. How do > I check to see if an error is being passed and if so show > error_messages_for?<%= render_errors @object %>> > b) From what I understood while playing around if I use a > render_action the > error message will be passed but if I do a redirect_to the errors are > not > passed. How can I use a render_action when the action I want to > render if I > get an error is in another controller?There''s a big conceptual difference between render_action and redirect_to. The former just selects which template file the action will use. It will not jump to another action at all. The latter, however, is an external redirect, it causes the browser to jump to a totally different url.> > 2) This is a continuation from a question from before. Instead of > deleting a > record I mark it as deleted. If I mark a post as deleted I also want > to mark > the comments associated with it as deleted. I tried the following and > it did > not work: > > @comments = Comment.find_all "post_id = 1"A neat trick: @comments = Comment.find_all_by_post_id(1)> @comments.each do |comment| > comment.deleted = 1 > comment.save > end > > It did not work. Am I doing it the wrong way?I don''t see anything that shouldn''t work in your code. Are you sure that comment.save returns true (i.e. there is no validation errors)?> > 4) Some of the actions I want the user to have to authenticate himself > before > he/she can execute them. Any easy Rails way of doing it? I was > thinking of > just passing a username and password in the URL and verifying it for > each > action that needs validation.Check out login generator and Howto Authenticate (http://wiki.rubyonrails.com/rails/show/HowtoAuthenticate). Howtos are generally a good place to find this kind of tutorials.> > Thanks again for all your help guys :-).You''re welcome ;-) //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
John Baku
2005-Mar-10 19:31 UTC
Re: error messages, loops and saves, actionmailer and finaly authentication
Thanks for your answers... but does: render_errors even exist? Doesn''t seem to. :-) Quoting Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org>:> > On 10.3.2005, at 20:41, John Baku wrote: > > > Thanks to everyone who responded to my first set of questions. Not > > only did I > > get my questions answered but I improved my code and learned a couple > > new > > things. > > > > I think I prefer the mailing list over IRC... easier to follow :-) > > > > I have some more questions if you don''t mind. Some are Rails related > > and some > > are Ruby related. > > > > 1) This is concerning displaying error messages. I am assuming I > > should use > > error_messages_for "objectName". So there are a couple questions that > > go with > > this. > > > > a) If there is no errors being passed to the action then I get an > > error. How do > > I check to see if an error is being passed and if so show > > error_messages_for? > > <%= render_errors @object %> > > > > > b) From what I understood while playing around if I use a > > render_action the > > error message will be passed but if I do a redirect_to the errors are > > not > > passed. How can I use a render_action when the action I want to > > render if I > > get an error is in another controller? > > There''s a big conceptual difference between render_action and > redirect_to. The former just selects which template file the action > will use. It will not jump to another action at all. The latter, > however, is an external redirect, it causes the browser to jump to a > totally different url. > > > > > > > > 2) This is a continuation from a question from before. Instead of > > deleting a > > record I mark it as deleted. If I mark a post as deleted I also want > > to mark > > the comments associated with it as deleted. I tried the following and > > it did > > not work: > > > > @comments = Comment.find_all "post_id = 1" > > A neat trick: @comments = Comment.find_all_by_post_id(1) > > > @comments.each do |comment| > > comment.deleted = 1 > > comment.save > > end > > > > It did not work. Am I doing it the wrong way? > > I don''t see anything that shouldn''t work in your code. Are you sure > that comment.save returns true (i.e. there is no validation errors)? > > > > > 4) Some of the actions I want the user to have to authenticate himself > > before > > he/she can execute them. Any easy Rails way of doing it? I was > > thinking of > > just passing a username and password in the URL and verifying it for > > each > > action that needs validation. > > Check out login generator and Howto Authenticate > (http://wiki.rubyonrails.com/rails/show/HowtoAuthenticate). > > Howtos are generally a good place to find this kind of tutorials. > > > > > Thanks again for all your help guys :-). > > You''re welcome ;-) > > //jarkko > > -- > Jarkko Laine > http://jlaine.net > http://odesign.fi >
Jarkko Laine
2005-Mar-10 20:03 UTC
Re: error messages, loops and saves, actionmailer and finaly authentication
On 10.3.2005, at 21:31, John Baku wrote:> Thanks for your answers... but does: > > render_errors > > even exist? Doesn''t seem to. :-)Oops, it was in the application_helper :-) def render_errors(obj) return "" unless obj tag = String.new unless obj.errors.empty? tag << %{<ul class="objerrors">} obj.errors.each_full do |message| tag << "<li>#{message}</li>" end tag << "</ul>" end tag end //jarkko> > Quoting Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org>: > >> >> On 10.3.2005, at 20:41, John Baku wrote: >> >>> Thanks to everyone who responded to my first set of questions. Not >>> only did I >>> get my questions answered but I improved my code and learned a couple >>> new >>> things. >>> >>> I think I prefer the mailing list over IRC... easier to follow :-) >>> >>> I have some more questions if you don''t mind. Some are Rails related >>> and some >>> are Ruby related. >>> >>> 1) This is concerning displaying error messages. I am assuming I >>> should use >>> error_messages_for "objectName". So there are a couple questions >>> that >>> go with >>> this. >>> >>> a) If there is no errors being passed to the action then I get an >>> error. How do >>> I check to see if an error is being passed and if so show >>> error_messages_for? >> >> <%= render_errors @object %> >> >>> >>> b) From what I understood while playing around if I use a >>> render_action the >>> error message will be passed but if I do a redirect_to the errors are >>> not >>> passed. How can I use a render_action when the action I want to >>> render if I >>> get an error is in another controller? >> >> There''s a big conceptual difference between render_action and >> redirect_to. The former just selects which template file the action >> will use. It will not jump to another action at all. The latter, >> however, is an external redirect, it causes the browser to jump to a >> totally different url. >> >> >> >> >>> >>> 2) This is a continuation from a question from before. Instead of >>> deleting a >>> record I mark it as deleted. If I mark a post as deleted I also want >>> to mark >>> the comments associated with it as deleted. I tried the following >>> and >>> it did >>> not work: >>> >>> @comments = Comment.find_all "post_id = 1" >> >> A neat trick: @comments = Comment.find_all_by_post_id(1) >> >>> @comments.each do |comment| >>> comment.deleted = 1 >>> comment.save >>> end >>> >>> It did not work. Am I doing it the wrong way? >> >> I don''t see anything that shouldn''t work in your code. Are you sure >> that comment.save returns true (i.e. there is no validation errors)? >> >>> >>> 4) Some of the actions I want the user to have to authenticate >>> himself >>> before >>> he/she can execute them. Any easy Rails way of doing it? I was >>> thinking of >>> just passing a username and password in the URL and verifying it for >>> each >>> action that needs validation. >> >> Check out login generator and Howto Authenticate >> (http://wiki.rubyonrails.com/rails/show/HowtoAuthenticate). >> >> Howtos are generally a good place to find this kind of tutorials. >> >>> >>> Thanks again for all your help guys :-). >> >> You''re welcome ;-) >> >> //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 >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails