Code Monkey home page Code Monkey logo

sinatra-nested-forms-lab-superheros's Introduction

Sinatra Nested Forms Lab: Superheroes!

Overview

In this lab, you'll practice building nested forms in Sinatra for creating teams of superheroes. No database is required, but feel free to add persistence after you have successfully completed the instructions below.

Instructions

Make a form

  1. Create a route that responds to a GET request at /.
  2. Create a view with a form and render it in the GET / route.
  3. The form should have fields for the name of a superhero team and their motto.
  4. There should be form inputs for each of the three superhero members' name, power, and bio.

It should look something like this:

super_hero.erb

Handle form submission

  1. Create a route that responds to a POST request at /teams.
  2. Have the form send a POST request to this route.
  3. Upon submission, render a template that displays the submitted team data and each member's data.

Final Output

Your params should be nested. For example, in order to see all the superheroes for the team you just created you would enter:

params["team"]["members"]

If you wanted to access the first superhero's name, you would enter:

params["team"]["members"][0]["name"]

When you post to this form you should render a page that displays the name of the team and each member of the team, including their name, super power and bio.

Your view should display something like this:

team.erb

Deliverables

Pass the tests! You'll notice in super_sinatra_spec.rb in the it submits the form test for 'POST /teams', we use the Capybara method fill_in:

fill_in("member1_name", :with => "Amanda")
fill_in("member1_power", :with => "Ruby")
fill_in("member1_bio", :with => "I love Ruby!")

The same pattern follows for the second and third superheroes. The word in quotes after fill_in needs to be set as an ID in the form to create the superheroes:

<input id="member1_name" type="text" name="team[members][][name]">

NOTE: If you run into any trouble with Sinatra's default configuration, such as needing to set the views directory for a particular controller (or to something other than the default views folder at the top level of your application directory), take a spin through the Sinatra configuration documentation, the Getting Started guide, or the old standbys, Google and StackOverflow.

Resources

sinatra-nested-forms-lab-superheros's People

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sinatra-nested-forms-lab-superheros's Issues

Third test

I had the technician assist me and we were not able to figure out why the 3rd test would not pass. I was able to submit my form and the information displayed on the site.

Learn IDE issues?

FYI - Daniel & I solved the problem of my lab, had all the tests passing then Learn IDE wouldn't let me submit it. I did another pull and the system threw a lot of garbage (======HEAD and other, more bizarre code) into my code. I cleaned it up as best I could and started getting an error message (

  1. App POST /teams submits the form
    Failure/Error: expect(page).to have_text("Hero Power: JavaScript")
    expected #has_text?("Hero Power: JavaScript") to return true, got false

    ./spec/super_sinatra_forms_spec.rb:40:in `block (3 levels) in <top (required)>') that we had resolved earlier.

Earlier today I had to reconnect Learn IDE because it wouldn't respond to Ctrl+C when I tried to get out of shotgun. Hope this is a temporary glitch!

Incomplete tests

For the final test, all you have to do is print out the motto to get it to pass

Unclear how to set `erb:` to look in `app/views`

A student pointed out that it was a bit unclear as to how to setup a sinatra app to look into app/views for the view rather than app/controllers/views.

The solution uses set :views, Proc.new { File.join(root, "../views/") } in the controller.
https://github.com/learn-co-curriculum/sinatra-nested-forms-lab-superheros/blob/solution/app/controllers/application_controller.rb#L5

Maybe we can add a hint for this somewhere? Or do we feel students should be able to figure this out on their own?

@cernanb @gj

Specification of Sinatra gem 1.4.3 is breaking click_button Capybara test

I'm getting the following error running the test suite:
1) App POST /teams submits the form Failure/Error: click_button 'submit' NoMethodError: undefined method 'join' for #<String:0x00000000041ce040>

I added value="submit" and id="submit" to the html but still no luck in getting Capybara to successfully click the button.

Removing the 1.4.3 version specification for the sinatra gem and running bundle update solves the issue.

Syntactic Errors with "spec/super_sinatra_forms_spec.rb"

Guys, I think there's a couple of issues with RSPEC in this lesson. Despite my code working well (and making sure to use the naming conventions specified for Capybara) I can't get it to pass and I keep getting syntax error messages for RSPEC. I found a couple of things in the "spec/super_sinatra_forms_spec" but even after correcting them I couldn't get my tests to pass:

Line 1 should be : describe "App" do it's missing the quotation marks around the class name "App".
Line 3 should be : describe "GET'/' " do the quotation marks are misplaced.

The only thing I could find was the following line was missing from the spec_helper file:
require 'capybara/dsl'

I'm still receiving the following errors related to RSPEC but need to move on to my next assignment sorry and it's still a bit over my head. Hope this helps :)

Failures:

  1. App GET '/' returns a 200 status code
    Failure/Error: get '/'
    NoMethodError:
    undefined method `get' for #RSpec::ExampleGroups::App::GET:0x00000001bab408
    Did you mean? gets
    gem

    ./spec/super_sinatra_forms_spec.rb:5:in `block (3 levels) in <top (required)>'

  2. App GET '/' renders super hero form
    Failure/Error: get '/'
    NoMethodError:
    undefined method `get' for #RSpec::ExampleGroups::App::GET:0x00000001ba9d60
    Did you mean? gets
    gem

    ./spec/super_sinatra_forms_spec.rb:5:in `block (3 levels) in <top (required)>'

  3. App POST /teams submits the form
    Failure/Error: visit '/'
    NoMethodError:
    undefined method `visit' for #RSpec::ExampleGroups::App::POSTTeams:0x00000001b9ff18

    ./spec/super_sinatra_forms_spec.rb:21:in `block (3 levels) in <top (required)>'

Looks like in the slack channel other folks are having the same issue..

environment.rb suggestion

Note - disregard - I understand why I was having a problem earlier. I didn't realize an application controller had already been started (I had tried to create my own app.rb file the way things had been structured in previous labs)

Hi there - just a suggestion, I don't know if it was intended to be part of the challenge of this lab, but I am using the Learn IDE and could not get anything to work at all until I changed the following in the environment.rb file
from: require_all 'app'
to: require './app'

This was not easily identified as a problem via error messaging and was really frustrating given I couldn't even get "get '/' do..." to work after so many other labs. I tried the above change based on comparing the environment file in this lab to the environment files in other labs.

David

Gemfile.lock issue

Hey there, I encountered this error while running bundle install.

/Users/helloamandamurphy/.rvm/gems/ruby-2.5.3/gems/nokogiri-1.6.6.2/ext/nokogiri
/Users/helloamandamurphy/.rvm/rubies/ruby-2.5.3/bin/ruby -r
./siteconf20190320-94606-ue0t3j.rb extconf.rb
checking if the C compiler accepts ... yes
checking if the C compiler accepts
-Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using packaged libraries.
-----
The file "/usr/include/iconv.h" is missing in your build environment,
which means you haven't installed Xcode Command Line Tools properly.

To install Command Line Tools, try running `xcode-select --install` on
terminal and follow the instructions.  If it fails, open Xcode.app,
select from the menu "Xcode" - "Open Developer Tool" - "More Developer
Tools" to open the developer site, download the installer for your OS
version and run it.
-----
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
	--with-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/Users/helloamandamurphy/.rvm/rubies/ruby-2.5.3/bin/$(RUBY_BASE_NAME)
	--help
	--clean
	--use-system-libraries
	--enable-static
	--disable-static
	--with-zlib-dir
	--without-zlib-dir
	--with-zlib-include
	--without-zlib-include=${zlib-dir}/include
	--with-zlib-lib
	--without-zlib-lib=${zlib-dir}/lib
	--enable-cross-build
	--disable-cross-build

To see why this extension failed to compile, please check the mkmf.log which can
be found here:

/Users/helloamandamurphy/.rvm/gems/ruby-2.5.3/extensions/x86_64-darwin-18/2.5.0/nokogiri-1.6.6.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
/Users/helloamandamurphy/.rvm/gems/ruby-2.5.3/gems/nokogiri-1.6.6.2 for
inspection.
Results logged to
/Users/helloamandamurphy/.rvm/gems/ruby-2.5.3/extensions/x86_64-darwin-18/2.5.0/nokogiri-1.6.6.2/gem_make.out

An error occurred while installing nokogiri (1.6.6.2), and Bundler
cannot continue.
Make sure that `gem install nokogiri -v '1.6.6.2' --source
'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  capybara was resolved to 2.5.0, which depends on
    xpath was resolved to 2.0.0, which depends on
      nokogiri```

I had this issue with a previous lab, and resolved it by deleting the Gemfile.lock file, so maybe take a look at that file for the other students.

doesn't use MVC file structure

By this point, students have already built out Sinatra using an app directory with separate directories for models, views, and controllers, similar to the basic forms lab. Students were confused as to why the controller was in the root of the directory.

If we want to reinforce MVC more, it would be better if all of the Sinatra labs used the MVC pattern.

Not working

The github link does not work. I forked and cloned from the raise issue link. The tests are not linked to learn. I completed and passed but Learn does not recognize any connection.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.