Giter VIP home page Giter VIP logo

rails-form_tag-lab's Introduction

Rails form_tag Lab

Objectives

  1. Build a functional Rails form using a form_tag
  2. Pass a route helper as the argument to a form_tag
  3. Pass an options hash with a method to a form_tag
  4. Use a text_field_tag and other form controls to create inputs
  5. Build a new action that renders a form that submits to the create action

Instructions

The two specs for this lab that are currently failing are located within the form page feature in specs/features/student_spec.rb.

For this lab, you need to build a form to create a new student, create a new student using params in the create route, and redirect to the index route to display all the students. Below are a few items to keep in mind:

  • Draw a new and create route for the students resource
  • Create a student using the data from the form via params. If you're not sure how the params are being sent from the form, use byebug in your route or puts to display the params in the terminal.
  • Redirect to the index route where all students will be displayed

Keys to remember

  • Look at the tests to see which field values you should be using

  • Make sure to use the form_tag helpers

Resources

rails-form_tag-lab's People

Contributors

annjohn avatar aspenjames avatar danielseehausen avatar dependabot[bot] avatar howardbdev avatar ihollander avatar jmburges avatar jordanhudgens avatar lizbur10 avatar maxwellbenton avatar perpepajn25 avatar pletcher avatar rrcobb avatar sgharms avatar victhevenot avatar

Watchers

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

rails-form_tag-lab's Issues

secrets.yml error

This lab also has an error when you run rspec or learn that it is missing secrets.yml.

Missing Secrets.yml

I've cloned the curriculum version just to be able to do something this morning. I will not create a PR but will copy my work into the students version. I hope this is ok.

The lab is missing a 'secrets.yml' file in the config dir:

Failures:

  1) Route to view has an index page
     Failure/Error: visit students_path
     RuntimeError:
       Missing `secret_token` and `secret_key_base` for 'test' environment, set these values in `config/secrets.yml`
     # ./spec/features/student_spec.rb:5:in `block (2 levels) in <top (required)>'

Fix: create 'config/secrets.yml' and paste this in it:

# Be sure to restart your server when you modify this file.

# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!

# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
# You can use `rake secret` to generate a secure secret key.

# Make sure the secrets in this file are kept private
# if you're sharing your code publicly.

development:
  secret_key_base: 45d07cfd3126c14dc8abf974c10022546b1a1d23c16485239ef1a09a299423d4e92968b3e7fd14f32177be066facdcea7d78ca54d22c394bf552ea15292262aa

test:
  secret_key_base: 1358fac7a48981852033f4d7a54c21a34272f92ca1ff35b7022de9131a1e13f5dde61b85fa439d9abfc53ba1a836e805be833b36fe0af6486641fd5a9cb69302

# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

Sentence at the bottom should be deleted

Hi. There's a sentence at the bottom of this lab that (I think) is only supposed to be visible if the user is logged out: "View Rails form_tag Lab on Learn.co and start learning to code for free."

Right now, it is ALSO visible when the user is logged in.

---Sdcrouse

redirection should be toward index, not new

"At a high level, you need to build a form to create a new student, have the form redirect back to the new view template, and print out the form params to the screen. Below are a few items to keep in mind:" - README

"you need to have students controller and form redirect to students path which is index" - Abdoul Diallo (after tests passing when switched to index)

```

Prefix Verb URI Pattern Controller#Action
students GET /students(.:format) students#index
POST /students(.:format) students#create
new_student GET /students/new(.:format) students#new
student GET /students/:id(.:format) students#show

Is there a better way to introduce the Create action?

This lab suffers from the same problem as the previous lesson โ€“โ€“ it instructs us to make the create action redirect to the new action and print out the params hash instead of following a more logical/realistic Rails flow and redirecting it to index or show.

Seems like a less-than-ideal way to introduce students to the create action in Rails.

Bundler Error

When I clone the repository and enter `"learn" I face this error:

Bundler could not find compatible versions for gem "bundler":
In Gemfile:
rails (~> 4.2) was resolved to 4.2.10, which depends on
bundler (>= 1.3.0, < 2.0)

Current Bundler version:
bundler (2.0.1)
This Gemfile requires a different version of Bundler.
Perhaps you need to update Bundler by running gem install bundler?

Could not find gem 'bundler (>= 1.3.0, < 2.0)', which is required by gem 'rails (~> 4.2)', in any of the sources.

sqlite3_adapter has conflict with new version of sqlite3 gem

This error appears on several of the Rails labs on Learn.co


Gem::LoadError:
  Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).```

Fix can be found here: https://github.com/rails/rails/issues/35153

Test requirement doesn't match convention taught in curriculum

In rails-form_tag-readme we are taught that Rails convention is to format our text field tags like:

<%= text_field_tag :'student[name]' %>

with a nested hash so our params are formatted correctly. When we get to rails-form_tag-lab in the spec/features/student_spec.rb on lines 29 and 30, Capybara is expecting our attributes to be:

fill_in 'first_name', with: "Margaery"
fill_in 'last_name', with: "Tyrell"

This requires us to not use the nested hash convention and simply create our text_field_tag like:

<%= text_field_tag :'first_name' %>

I believe this should be fixed because in the curriculum we are taught to use nested hashes but in the test it is looking for just the attribute. I edited lines 29 and 30 to say:

fill_in '[student]first_name', with: "Margaery"
fill_in '[student]last_name', with: "Tyrell"

and it worked when my code used nested hashes. I assume that since Capybara is looking for a string in its fill_in method it depends upon the syntax to be exact. I think for the purpose of consistency it is better to have Capybara look for the nested hash syntax rather than just the attribute.

spec/features/student_spec.rb

Was working with a student on this lab and he seemed to be using form_tag correctly and doing exactly as he was asked to do. Finally compared the spec files of the solution branch and his master branch. There are small differences on lines 29 and 30 which I have pasted in screenshots below. I had him change his spec file (which I know students are not supposed to do). I first tried to alter his code to match what was going on in the spec file but couldn't seem to get it to work. Not sure if this is an error in the spec or I was just not understanding how to code to what the spec was looking for?

code from spec/features/student_spec.rb:29-30 in solution branch:
solution
code from spec/features/student_spec.rb:29-30 in master branch:
master

display params on new view page

`def create
# byebug
@Student = Student.create(first_name: params[:student][:first_name], last_name: params[:student][:last_name])

redirect_to new_student_path

end`

The instructions explicitly say to redirect back to the new view page. I was unable to get the tests to pass after two coaches helped me and said my code looked good. the tests passed when redirected to the show page though.

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.