learn-co-curriculum / basic-nested-forms Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
Copy and pasting from a previous issue that was closed but not revised!
This lesson instructs you to use "f.fields_for", but the fields only appear when the syntax is entered as "fields_for", without the "f."
Lab will not mark as complete.
When I started the lab, there was a repo to fork, which I did. Now lab has correctly converted to a readme. I have two green lights, but lab does not register as complete.
I noticed since a couple of lessons ago, the way the material is being presented is very different than how the curriculum has been teaching the concepts until now. I feel these last lessons have been a bit scarce, lacking in explanation and elucidation of the concepts. I understand we are now at a more advanced point in the curriculum, but new concepts are still being introduced. As such, I strongly recommend "enriching" these last section of the curriculum, spending just a few more lines explaining new concepts and HOW the methods work.
Just my humble opinion. Trying to be helpful.
I'm not sure if this is intentional, but this lab seems to be using Minitest instead of RSpec. I couldn't get learn
to run tests locally without adding my own specs.
In the end with keys like "0" and one
Hi there, the rails console in this lab also isn't working properly based on the information provided in the lesson. Stumbled upon this error after entering these two Terminal Commands: new_person = Person.new
followed by: new_person.save
According to the lesson, the output in the terminal from the rails console should be:
Hope this helps!!
Thanks, again
I ran into this error while trying to get started on this lab.
Bundler could not find compatible versions for gem "bundler":
In Gemfile:
rails (~> 4.2) was resolved to 4.2.11.1, 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.
This exercise is structured as a lab when it should be a readme. I can't get learn to mark it as complete because there are no tests to pass.
It is never stated where params is created or written. If this is not supposed to be the case, running the command based on what is in the lab returns nothing in the console.
Missing String email in Person model, yet referenced in nested attributes hash.
This lesson instructs you to use "f.fields_for", but the fields only appear when the syntax is entered as "fields_for", without the "f."
I'm getting this message when I try to view the console and server.
/.rvm/gems/ruby-2.6.1/gems/activerecord-5.2.3/lib/active_record/dynamic_matchers.rb:22:in
method_missing': undefined method raise_in_transactional_callbacks=' for ActiveRecord::Base:Class (NoMethodError)
Not sure what's going on there.
They're no specs in the test for a local test to pass.
Hi, I think there is an error in this lab's example code in the "Avoiding Duplicates" section. This is the example provided:
class Song < ActiveRecord::Base
def artist_attributes=(artist)
self.artist = Artist.find_or_create_by(name: artist.name)
self.artist.update(artist)
end
end
I noticed is that you are shadowing an instance variable's name artist
with the local variable artist
which can be confusing, and I think led to an error in this case. In the line self.artist = Artist.find_or_create_by(name: artist.name)
self.artist on the left-hand side of the assignment is the instance variable @artist (which is an instance of the Artist class or nil) but the artist.name
in the argument references the local variable (which will have "preference" in this scope). As such, artist (without a prefix of @ or self-dot) refers to the attribute hash passed in, so artist.name will cause a NoMethodError. To make this code work, I think it needs to be Artist.find_or_create_by(name: artist[:name])
. You do want to reference the local variable here, but the artist
local variable is a hash object, not an Artist instance, so it has no method name
- to get the name information of the local variable you need to use artist[:name]
.
It seems to me like it would be less easy to fall into making the mistake between the two if you renamed the local variable something like artist_info
or artist_hash
, and then changed the third line down to
self.artist = Artist.find_or_create_by(name: artist_info[:name])
or something like that.
Thanks!
I built a test for this lab (which was great fun!), but I'm not sure if we are supposed to do that. If so, could add a line to the lab saying, "Please build test(s) to check the validity of this form, using Capybara." Otherwise, there is no way to progress to the next lesson.
In the Rails Basic Nested Forms reading, is the "Avoiding Duplicates" section saying that when we want to avoid duplicates of the row we're creating, that we don't use accepts_nested_attributes_for ? And in those situations we just create a setter method such in as the example below that with songs and artists?
**people and addresses: you can have multiple people with the same address, so in the Person class, accepts_nested_attributes_for :addresses is ok.
**songs and artists: you can't have duplicates of the artists, because you want to be able to return all of the songs associated with that artist and if the artist is listed more than once, it may not be accurate. So in the Song class, there is no accepts_nested_attributes_for, but instead an artist_attributes= method.
So how come in the Rails Has Many Through in Forms lab, our Post class can still pass the tests with an accepts_nested_attributes_for :categories plus a categories_attributes= method?
in text snippet
<%= fields_for :addresses do |addr| %>
There are no rspec tests present, so learn
never returns complete and the lab cannot be marked as done.
This is my Gemfile (what I had to change to get bundle install
to run.)
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2', '>= 5.2.3'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0', '>= 5.0.7'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 5.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails', '~> 4.3', '>= 4.3.3'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem 'pry'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
# gem 'spring'
end
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.