Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ASPhillips8
Copy link

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
Screenshot 2024-08-09 at 6 37 15 AM
Screenshot 2024-08-09 at 6 37 31 AM

Copy link

@stephenmckeon stephenmckeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job!!!

Comment on lines +6 to +11
@name = name
@weight = weight
@height = height
@@prirates << self
end

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.

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])

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:

Suggested change
@pirate = Pirate.new(params[:pirate][:name], params[:pirate][:weight], params[:pirate][:height])
@pirate = Pirate.new(params[:pirate])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants