-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display Nested Form Data #16
base: master
Are you sure you want to change the base?
Display Nested Form Data #16
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job!!!
@name = name | ||
@weight = weight | ||
@height = height | ||
@@prirates << self | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then this would become very simple:
@pirate = Pirate.new(params[:pirate][:name], params[:pirate][:weight], params[:pirate][:height]) | |
@pirate = Pirate.new(params[:pirate]) |
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