How to display the result of form input

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

How to display the result of form input
How to display 0 on the left side of the standard input value
How to display the select field of time_select every 30 minutes
How to sort the List of SelectItem
[Rails] How to omit the display of the character string of the link_to method
How to find the cause of the Ruby error
Customize how to divide the contents of Recyclerview
How to get today's day of the week
[Ruby] Code to display the day of the week
[Java] How to get the authority of the folder
How to display the amount of disk used by Docker container for each container
[Ruby on Rails] How to Japaneseize the error message of Form object (ActiveModel)
[Java] How to get the URL of the transition source
How to delete / update the list field of OneToMany
How to set the display time to Japan time in Rails
How to write Scala from the perspective of Java
[Rails, JS] How to implement asynchronous display of comments
[Ruby] How to find the sum of each digit
How to install the root certificate of Centos7 (Cybertrust)
[Java] How to get the maximum value of HashMap
I want to display the name of the poster of the comment
[Rails] How to change the column name of the table
[SwiftUI] How to specify the abbreviated position of Text
[Android] How to get the setting language of the terminal
[Rails] How to get the contents of strong parameters
How to judge the click of any area of the image
How to download the old version of Apache Tomcat
[Swift] How to get the document ID of Firebase
[Rails] How to display an image in the view
[Java] How to display Wingdings
Input to the Java console
[Java] How to display the day of the week acquired by LocalDate, DateTimeformatter in Japanese
[Rails] How to display the weather forecast of the registered address in Japanese using OpenWeatherMap
How to create a form to select a date from the calendar
How to get the longest information from Twitter as of 12/12/2016
How to change the setting value of Springboot Hikari CP
[Ruby] How to retrieve the contents of a double hash
Let's summarize how to extend the expiration date of Rails
How to solve the problems of Java's three Blocking Queues
How to mock some methods of the class under test
How to implement one-line display of TextView in Android development
How to derive the last day of the month in Java
How to change the contents of the jar file without decompressing
How to check the extension and size of uploaded files
I want to narrow down the display of docker ps
Be sure to compare the result of Java compareTo with 0
[jsoup] How to get the full amount of a document
[Rails] How to display information stored in the database in view
How to check the database of apps deployed on Heroku
How to use the link_to method
How to use the include? method
How to use the form_with method
[rails] How to display db information
How to find the average angle
How to use the wrapper class
[Java] Input to stdin of Process
How to use setDefaultCloseOperation () of JFrame
How to add the delete function
[Ruby] Display the contents of variables
Filter the result of BindingResult [Spring]
[Swift] How to dynamically change the height of the toolbar on the keyboard