Re: [Rails] Re: Newbie code review

2015-07-04 Thread Colin Law
On 4 July 2015 at 03:40, Federicko fedom...@gmail.com wrote: Hi Colin, I have done that but slightly differently as the 'this' variable was giving me an error. Sorry it should have been 'self' not 'this' of course, as I am sure you worked out. ruby != c++ Controller didn't change. It

Re: [Rails] Re: Newbie code review

2015-07-03 Thread Federicko
Hi Colin, I have done that but slightly differently as the 'this' variable was giving me an error. Controller didn't change. It still just calls the rankup or rankdown methods in the model. Here's the code for that: def rank @this_article = Article.find(params[:id]) if (params[:rank] ==

[Rails] Re: Newbie code review

2015-07-03 Thread Federicko
Thanks for the detailed post. I will definitely check out the gem -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to

Re: [Rails] Re: Newbie code review

2015-07-02 Thread Colin Law
On 2 July 2015 at 11:07, Federicko fedom...@gmail.com wrote: OK, so I have modified the code following Colin's suggestion. Check it out: In the controller, my action is as follows: def rank @this_article = Article.find(params[:id]) if (params[:rank] == 'up')

[Rails] Re: Newbie code review

2015-07-02 Thread Federicko
OK, so I have modified the code following Colin's suggestion. Check it out: In the controller, my action is as follows: def rank @this_article = Article.find(params[:id]) if (params[:rank] == 'up') @this_article.rankup(params[:rank]) else @this_article.rankdown(params[:rank])

[Rails] Re: Newbie code review

2015-07-02 Thread Federicko
Oh yeah, like this? In controller: def rank @this_article = Article.find(params[:id]) if (params[:rank] == 'up') @this_article.rankup else @this_article.rankdown end redirect_to articles_path() end In the model: def rankup() @affected_article = Article.find_by(ranking:

Re: [Rails] Re: Newbie code review

2015-07-02 Thread Colin Law
On 2 July 2015 at 12:04, Federicko fedom...@gmail.com wrote: Oh yeah, like this? In controller: def rank @this_article = Article.find(params[:id]) if (params[:rank] == 'up') @this_article.rankup else @this_article.rankdown end redirect_to articles_path() end In

[Rails] Re: Newbie code review

2015-07-02 Thread Elizabeth McGurty
CORRECTION: Had a little fun with acts_as_list... . -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To

[Rails] Re: Newbie code review

2015-07-02 Thread Elizabeth McGurty
Had a little fun with acts_like_list... Build in Rails 3, should work in Rails 4 though??? Add to your gem file: gem 'acts_as_list' Run: bundle install Add the field position as an integer to your Articles table: From rails console: RUN: rails g migration AddPositionToArticle

Re: [Rails] Re: Newbie code review

2015-07-01 Thread Federicko
Yeah, I will check that gem out. I basically wanted to do this to learn the ways of the Rails :p -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to

Re: [Rails] Re: Newbie code review

2015-07-01 Thread Colin Law
On 1 July 2015 at 09:33, Federicko fedom...@gmail.com wrote: Yeah, I will check that gem out. I basically wanted to do this to learn the ways of the Rails :p In that case I would have two member methods rankup and rankdown that do everything, including saving, all wrapped in a transaction. So

[Rails] Re: Newbie code review

2015-07-01 Thread Frederick Cheung
On Tuesday, June 30, 2015 at 4:46:40 PM UTC+1, Federicko wrote: Yes but I also call those method from the Class method rank and it needs to save. This is always my dilemma, just exactly what or how much code should go into controller and model? Like in my example, before when I had

Re: [Rails] Re: Newbie code review

2015-07-01 Thread Colin Law
On 1 July 2015 at 05:06, Federicko fedom...@gmail.com wrote: Hi All, First of all, let me quickly clarify the meaning of ranking here. All I'm doing is move an article up or down in the display on the index file. Quick example. Below is a sample of the Articles table: ID title

[Rails] Re: Newbie code review

2015-06-30 Thread Federicko
Hi All, First of all, let me quickly clarify the meaning of ranking here. All I'm doing is move an article up or down in the display on the index file. Quick example. Below is a sample of the Articles table: ID titleranking 5 Rails is cool

[Rails] Re: Newbie code review

2015-06-30 Thread Federicko
Yes but I also call those method from the Class method rank and it needs to save. This is always my dilemma, just exactly what or how much code should go into controller and model? Like in my example, before when I had everything in the controller, people suggested that I put that code in the

[Rails] Re: Newbie code review

2015-06-30 Thread Ivan Lasorsa
Maybe take out the save from rankup and rankdown and save in the controller? -- 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 unsubscribe from this group and stop receiving emails from it,

[Rails] Re: Newbie code review

2015-06-29 Thread Federicko
Hi All, Thank for the feedback. Yeah, my next step is to consolidate the two actions together. Good point on using POST instead of GET. I will change the link_to helper. As to using generators, I followed the tutorial and used generators for creating the model and controllers for Articles and

[Rails] Re: Newbie code review

2015-06-28 Thread Elizabeth McGurty
Jeez For a first time effort, you have done an excellent job... Seems that you have great instincts.. I don't see your form here, but defs rankup an rankdown should be consolidated into a controller action 'update'. What's the name of your view? Seems here it should be called list. If I

Re: [Rails] Re: Newbie code review

2015-06-28 Thread Colin Law
On 28 June 2015 at 22:15, Elizabeth McGurty emcgur...@gmail.com wrote: Jeez For a first time effort, you have done an excellent job... Seems that you have great instincts.. I don't see your form here, but defs rankup an rankdown should be consolidated into a controller action 'update'.