Hi guys! More question :P~
OK, I'm following a tutorial for rail, and I got this new.html.erb in
views, and in order for a form to be showed up correctly without error,
I had to add this small snippet of code in the controller under method
class AdsController < ApplicationController
2 def show
3 @ad = Ad.find(params[:id])
6 def index
7 @ads = Ad.find(:all)
10 def new
11 @ad = Ad.new
My question is, I thought this would be creating an error because I have
def show using variable @ad, and then def new also using variable @ad,
but instead of any glitch, I got the rail app works out perfectly.
I'm new to ruby and the programming world and especially rail. I just
wonder is this a good practice? It's like overwrite what @ad in "def
show" when user wants to get action "def new." Or maybe I got confused?
Rails has all variable in each method as local? Or each time each
action/method gets executed, it will be newly object in memory anyway,
and so it won't be affected by the code/abstract above? Please help me
understand this, thanks...