Display Nested Form Data#16
Open
ASPhillips8 wants to merge 3 commits intolearn-co-students:masterfrom
Open
Conversation
stephenmckeon
approved these changes
Aug 9, 2024
Comment on lines
+6
to
+11
| def initialize(name, weight, height) | ||
| @name = name | ||
| @weight = weight | ||
| @height = height | ||
| @@prirates << self | ||
| end |
There was a problem hiding this comment.
The other option that you have here would be to pass one argument here, like params, and pull the attributes out of that, just like you did in Ship.
Suggested change
| def initialize(name, weight, height) | |
| @name = name | |
| @weight = weight | |
| @height = height | |
| @@prirates << self | |
| end | |
| def initialize(params) | |
| @name = params[:name] | |
| @weight = params[:weight] | |
| @height = params[:height] | |
| @@prirates << self | |
| end |
| end | ||
|
|
||
| post '/pirates' do | ||
| @pirate = Pirate.new(params[:pirate][:name], params[:pirate][:weight], params[:pirate][:height]) |
There was a problem hiding this comment.
Then this would become very simple:
Suggested change
| @pirate = Pirate.new(params[:pirate][:name], params[:pirate][:weight], params[:pirate][:height]) | |
| @pirate = Pirate.new(params[:pirate]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Created classes for pirate and ship with class methods. Created route to root to display instructions. Created route to /new that displayed form for creating new instance of both ship and pirate. Created route that shows new instance of pirate and nested ship

