在 Rails 中,我们定义了create
2 种方式的动作。有什么区别?
def create
@shop = Shop.new(params[:shop])
if @shop.save
flash[:success] = 'Thanks for adding new shop.'
redirect_to @shop
else
flash[:error] = 'Error adding review, please try again.'
redirect_to @shop
end
end
# or
def create
@shop = Shop.create(params[:shop])
if @shop.save
flash[:success] = 'Thanks for adding new shop.'
redirect_to @shop
else
flash[:error] = 'Error adding review, please try again.'
redirect_to @shop
end
end
考虑到我们已经有:
def new
@shop = Shop.new
end
哪个更合适?