I will write an article for the first time I'm a beginner for a month since I started learning programming
I am creating a furima app with ruby on rails When you register as a user, list an item, and another user purchases it, the transaction is completed.
In the specifications at this stage, when the user finishes inputting the exhibited product, it will move to the top page.
def create
@item = Item.new(item_params)
if @item.valid?
@item.save
return redirect_to root_path #Return to top page
else
render :new
end
end
Here, I am considering how to add a page that says "Product listing is complete" and click back to the top page.
--Try by writing the path in the controller
First, create an HTML document for displaying the results (let's call it kanryou) Described in the routes file
resources :items do
resources :orders, only: [:index, :create]
member do
get 'kanryou'
end
end
Described in the controller
def create
@item = Item.new(item_params)
if @item.valid?
@item.save
return redirect_to kanryou_item_path(@item.id)
else
render :new
end
end
That worked
I was allowed to reference https://qiita.com/imayasu/items/19f43a5726ed2170f611
Recommended Posts