Home>
I'm using an app in Rails, but when I use two renders, I get an error
Please teach me how to do these two processes.
controller
def create
@tweet = Tweet.create (tweet_params)
return redirect_to tweets_path if @ tweet.save
render "new"
render layout: "application"
end
The first is a render to redraw the screen if @tweet is not saved
The second is a render to use a different layout file
Write return after the first render
However, when return is used, it seems that the subsequent processing is not executed and the second render is not executed.
def create
@tweet = Tweet.create (tweet_params)
return redirect_to tweets_path if @ tweet.save
render "new" and return
render layout: "application"
end
Write render layout earlier
def create
@tweet = Tweet.create (tweet_params)
ender layout: "application"
return redirect_to tweets_path if @ tweet.save
render "new" and return
end
Another error occurred
-
Answer # 1
-
Answer # 2
Please separate the process itself.
Only one result can be given to one controller. (Same for all languages and frameworks)It doesn't seem to be rendered separately depending on the conditions, and please prepare two methods in the controller and execute them in order.
Related articles
- i want to have data for each prefecture with ruby on rails
- ruby on rails - i want to display a list of liked data
- ruby on rails - i want to eliminate nomethoderror
- ruby on rails - i want to save data in an intermediate table
- ruby on rails - i want to set responsestatus to 200, but it becomes 401
- ruby on rails - [rails] i want to pass json from controller to html (erb)
- ruby on rails - i want to erase www on heroku
- ruby on rails - i want to sort the search results
- ruby on rails 6 - use the local wsdl file in the soap client
- ruby on rails 6 - i want to save data from one form to multiple tables at the same time
- ruby on rails - how to use requestreferer
- ruby on rails - i want to move to the product purchase page
- ruby on rails - i want to launch rails with a new file
- ruby on rails - i want to save the purchase information in the db
- ruby on rails - i want to display the details page
- ruby on rails - i want to add a class to link_to
- ruby on rails - i want to display "sold out" when the product is sold
- ruby on rails - i want to deploy to aws ec2 server
- ruby on rails - i cannot save a comment on the comment posting page
Related questions
- ruby - sass :: syntaxerror on rails s
- javascript - i want the scroll bar to always appear at the bottom of the chat screen
- ruby - the top screen is displayed at http: // localhost: 3000/users/sign_in
- ruby - [rails] the class attribute specified by the div tag enclosed in simple_format is not applied
- ruby on rails removal function
- ruby on rails sorting
- html - i can't set the regular expression well
- ruby - rails i want to make the created_at time the same when creating multiple data at once
- ruby - dynamic form implementation in nested_form
Is it something like this?