Заполнение данных из массива для Rails API

#api

#API

Вопрос:

Следующий код находится в моем файле seeds.rb, первая часть представляет собой массив с данными, которые я хотел бы использовать.

     trails = [
    {
        Prop_ID: "B057",
        Name: "Salt Marsh Nature Trail",
        Location: "Enter behind the Salt Marsh Nature Center, located near the intersection of East 33rd Street and Avenue U.",
        Park_Name: "Marine Park",
        Length: "0.8 miles",
        Difficulty: nil,
        Other_Details: "The first half of this mile-long trail follows the shore of Gerritsen Beach, which empties into Jamaica Bay. The trailamp;rsquo;s second leg winds through a prairie of tall grass, where you can sometimes spot cottontail rabbits and ring-necked pheasants.<br>Check out our <a href="/park-features/hiking/marine-park">Marine Park Trails</a> page for a map and directions to scenic locations, and comfort stations and maps are also available inside the Salt Marsh Nature Center.",
        Accessible: "Y",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "B073",
        Name: "Lullwater",
        Location: "Enter Park at Lincoln Road and Ocean Avenue entrance.  Trails begin or are near the Prospect Park Audubon Center.",
        Park_Name: "Prospect Park",
        Length: "1.0 mile",
        Difficulty: "Easy",
        Other_Details: "Explore the Lullwater to see how nature thrives in the heart of Brooklyn.  The Lullwater is a great place to see birds and other wildlife.  Bathrooms, cafamp;eacute; and trail guides are available at the Prospect Park Audubon Center.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "B073",
        Name: "Midwood",
        Location: "Enter Park at Lincoln Road and Ocean Avenue entrance. Trails begin or are near the Prospect Park Audubon Center.",
        Park_Name: "Prospect Park",
        Length: "0.75 miles",
        Difficulty: "Easy",
        Other_Details: "Step back in time with a walk through Brooklynamp;rsquo;s oldest remaining forest. The Midwood, home to some of Prospect Parkamp;rsquo;s largest trees, is a relic of Brooklynamp;rsquo;s history, and was preserved and incorporated into the park during its original construction. The thirty-minute hike loops from Prospect Parkamp;rsquo;s Audubon Center through a forest filled with birds and other animals.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "B073",
        Name: "Peninsula",
        Location: "Enter Park at Lincoln Road and Ocean Avenue entrance.  Trails begin or are near the Prospect Park Audubon Center.",
        Park_Name: "Prospect Park",
        Length: "0.5 miles",
        Difficulty: "Easy",
        Other_Details: "Discover how the Peninsula has changed over the last 300 years.  The Peninsula's restored landscapes provide scenic views, a home for Park wildlife, and great fishing.  Bathrooms, cafamp;eacute; and trail guides are available at the Prospect Park Audubon Center.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "B073",
        Name: "Waterfall",
        Location: "Enter Park at Lincoln Road and Ocean Avenue entrance.  Trails begin or are near the Prospect Park Audubon Center.",
        Park_Name: "Prospect Park",
        Length: "0.5 miles",
        Difficulty: "Easy",
        Other_Details: "Trace the source of the Lake on the Waterfall trail.  The Fallkill Falls is the first of six waterfalls that you will see along the Park's watercourse.  Bathrooms, cafamp;eacute; and trail guides are available at the Prospect Park Audubon Center.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "Q001",
        Name: "Alley Pond Trails",
        Location: "Park-wide. Check out our <a href="/park-features/hiking/alley-pond-park">Alley Pond Park Trails</a> page for a map and directions to scenic locations.",
        Park_Name: "Alley Pond Park",
        Length: "Various",
        Difficulty: "Various",
        Other_Details: "Numerous trails wind through native hardwood (oak-hickory) forest and kettle ponds.  The north end of the park boasts splendid salt marsh views.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "Q015",
        Name: "Blue Trail",
        Location: "Forest Park Drive East, off of Woodhaven Boulevard",
        Park_Name: "Forest Park",
        Length: "1.7 miles",
        Difficulty: nil,
        Other_Details: "Forest Park's numerous trails wind through native hardwood (oak-hickory) forest and kettle ponds.<br>Check out our <a href="/park-features/hiking/forest-park">Forest Park Trails</a> page for a map featuring entrances and directions to scenic locations.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "Q015",
        Name: "Orange Trail",
        Location: "Memorial Drive and Forest Park Drive East",
        Park_Name: "Forest Park",
        Length: "2.4 miles",
        Difficulty: nil,
        Other_Details: "This trail will lead you through a 2.4 mile adventurous hike along the perimeter of the forest. <br>Check out our <a href="/park-features/hiking/forest-park">Forest Park Trails</a> page for a map featuring entrances and directions to scenic locations.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "Q015",
        Name: "Yellow Trail",
        Location: "Metropolitan Avenue amp; Forest Park Drive East",
        Park_Name: "Forest Park",
        Length: "1.0 mile",
        Difficulty: nil,
        Other_Details: "Check out our <a href="/park-features/hiking/forest-park">Forest Park Trails</a> page for a map featuring entrances and directions to scenic locations.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "Q021",
        Name: "South Preserve Trail",
        Location: "Francis Lewis Boulevard and Union Turnpike",
        Park_Name: "Cunningham Park",
        Length: "3.0 miles",
        Difficulty: nil,
        Other_Details: "Numerous unnamed trails wind through native hardwood (oak-hickory) forest, which features a diverse ecosystem to support abundant wildlife. The parksamp;rsquo; Kettle Ponds feature the sounds of Spring Peepers and other species of frogs throughout the spring and summer season.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "R013",
        Name: "Greenbelt Blue Trail (Southern Trailhead)",
        Location: "Brielle Avenue amp; Roanoake Street",
        Park_Name: "La Tourette Parks amp; Golf Course",
        Length: "12.3 miles",
        Difficulty: "Easy/Moderate",
        Other_Details: "This is the Greenbeltamp;rsquo;s longest marked trail.  Its northeastern trailhead at the Greenbeltamp;rsquo;s Deere Park can be accessed from Staten Island Boulevard.  Walk the trail to its end, near the Brielle Avenue-Roanoake Street intersection in Willowbrook, and you will either pass through or have a view of each of the Greenbeltamp;rsquo;s five distinct vegetation zones.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "R013",
        Name: "Greenbelt Nature Center Trail",
        Location: "Rockland amp; Brielle avenues",
        Park_Name: "La Tourette Parks amp; Golf Course",
        Length: "0.85 miles",
        Difficulty: "Easy",
        Other_Details: "This gentle walk takes you through a forest of red maple, black birch, cherry, tulip, and sassafras trees.  In the understory, there is an abundance of spicebush, which produces bright red berries in the fall.  The trail connects to the blue trail and the white trail.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "R013",
        Name: "Greenbelt Red Trail",
        Location: "Richmond Road and St. Patrick's Place",
        Park_Name: "La Tourette Parks amp; Golf Course",
        Length: "4.0 miles",
        Difficulty: "Easy/Moderate",
        Other_Details: "This loop trail is in the heart of the Greenbelt, which is also home to six other picturesque hiking trails on which urban explorers can discover Staten Islandamp;rsquo;s vast preserves of natural spaces. The red trail crosses over Buckamp;rsquo;s Hollow, Heyerdahl Hill, the northern edge of LaTourette golf course and the neighborhood of Lighthouse Hill. Want to make a full day of itamp;Alpha; A pathway leads from the trail downhill to Historic Richmond Town, where you can walk through a preserved 18th century village.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "R013",
        Name: "Greenbelt White Trail (Southern)",
        Location: "Rockland Avenue near Brielle Avenue (mid-way trailhead) or Richmond Road near Reidel Avenue",
        Park_Name: "La Tourette Parks amp; Golf Course",
        Length: "7.6 miles",
        Difficulty: "Easy/Moderate",
        Other_Details: "Connects to Great Kills Park of the Gateway National Park System Service.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "R013",
        Name: "Greenbelt Yellow Trail (Southwest Trailhead)",
        Location: "Richmond Avenue amp; Forest Hill Road",
        Park_Name: "La Tourette Parks amp; Golf Course",
        Length: "8.0 miles",
        Difficulty: "Moderate/Difficult",
        Other_Details: "Traverses the entire Greenbelt from its Northeast corner in the community of Todt Hill to its Southwest corner in  New Springville; access Moses' Mountain at Rockland Avenue and Manor Road behind bus stop.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "R017",
        Name: "William T. Davis Wildlife Refuge Pink Trail",
        Location: "Mulberry Avenue off Travis Avenue (limited parking)",
        Park_Name: "William T. Davis Wildlife Refuge",
        Length: "0.5 miles",
        Difficulty: "Easy",
        Other_Details: "Excellent birdwatching location; abounds with water-loving trees such as sweet gum and ash.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "R030",
        Name: "Willowbrook Park White Trail",
        Location: "Willowbrook Park off Victory Boulevard",
        Park_Name: "Willowbrook Park",
        Length: "7.6 miles",
        Difficulty: "Easy/Moderate",
        Other_Details: "Connects to Great Kills Park of the Gateway National Park System Service.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "R088",
        Name: "Gretta Moulton Trail/Green Trail",
        Location: "200 feet ahead of parking lot at the terminus of Nevada Avenue",
        Park_Name: "High Rock Park",
        Length: "0.75 miles",
        Difficulty: "Moderate",
        Other_Details: "The trail head of this circular trail is off the High Rock Park access road near the Nevada Avenue entrance.  The hike takes you along kettle ponds and knobs, formations characteristic of terminal moraine topography.  The upland forest includes a patch of persimmon trees.  The trail is also known as the Gretta Moulton Trail in honor of an ardent Greenbelt supporter.  Bathrooms nearby.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "R088",
        Name: "High Rock Park Lavender Trail",
        Location: "200 feet ahead of parking lot at the terminus of Nevada Avenue",
        Park_Name: "High Rock Park",
        Length: "0.25 miles",
        Difficulty: "Easy",
        Other_Details: "Jewelweed, skunk cabbage, and various grasses and water plants can be seen, along with black water snakes, snapping turtles, and spring peepers.  Bathrooms nearby.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "R115",
        Name: "Deere Park Blue Trail",
        Location: "Staten Island Boulevard",
        Park_Name: "Deere Park",
        Length: "12.3 miles",
        Difficulty: "Easy/Moderate",
        Other_Details: "This is the Greenbeltamp;rsquo;s longest marked trail.  Its northeastern trailhead at the Greenbeltamp;rsquo;s Deere Park can be accessed from Staten Island Boulevard.  Walk the trail to its end, near the Brielle Avenue-Roanoake Street intersection in Willowbrook, and you will either pass through or have a view of each of the Greenbeltamp;rsquo;s five distinct vegetation zones.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "X092",
        Name: "Cass Gallagher Nature Trail",
        Location: "A short walk in from the intersection of Broadway and Mosholu Avenue, near the horse stables.",
        Park_Name: "Van Cortlandt Park",
        Length: "1.4 miles",
        Difficulty: "Moderate/Difficult",
        Other_Details: "Check out our <a href="/park-features/hiking/van-cortlandt-park">Van Cortlandt Trails</a> page for a map and directions to scenic locations.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "X092",
        Name: "John Kieran Trail",
        Location: "Enter at Golf Course via Van Cortlandt Park South and Bailey Avenue.",
        Park_Name: "Van Cortlandt Park",
        Length: "1.25 miles",
        Difficulty: "Easy",
        Other_Details: "Maps are available at the Van Cortlandt Nature Center. Named in 1988 for the famed naturalist and newspaperman, this trail journeys through the park's lake area and freshwater wetlands, passing Tibbet's Brook via a wooden bridge perfect for birding, and forms a loop with the Parade Ground.<br>Check out our <a href="/park-features/hiking/van-cortlandt-park">Van Cortlandt Trails</a> page for a map and directions to scenic locations.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "X092",
        Name: "John Muir Trail",
        Location: "Enter either at Broadway amp; Mosholu Avenue or Van Cortlandt Park East amp; Oneida Avenue.",
        Park_Name: "Van Cortlandt Park",
        Length: "1.5 miles",
        Difficulty: "Moderate",
        Other_Details: "Travel through three ecologically distinct forests on this 1.5 mile route, the only trail in Van Cortlandt Park to traverse the park from east to west. The trail will lead you through park's Northeast Forest, home to red oak, sweetgum, and tulip trees, as well as a frog-filled marsh; the Croton Woods and its sugar maple and hickory trees, as well as the Old Croton Aqueduct; and the hilly Northwest Forest, home to stately tulip, oak, and hickory trees.<br>Check out our <a href="/park-features/hiking/van-cortlandt-park">Van Cortlandt Trails</a> page for a map and directions to scenic locations.",
        Accessible: "N",
        Limited_Access: "Y",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "X092",
        Name: "Old Croton Aqueduct Trail",
        Location: "Enter Trail at either Dickinson Avenue amp; Van Cortlandt Park South or Mosholu Parkway amp; West Gun Hill Road.",
        Park_Name: "Van Cortlandt Park",
        Length: "1.1 mile",
        Difficulty: "Easy/Moderate",
        Other_Details: "[Trail renovations will begin soon. Please bear with us as we correct erosion and rebuild paths.] This segment is part of the 41-mile-long aqueduct that brought water from the Croton Dam to New York City in the 1800s.<br>Check out our <a href="/park-features/hiking/van-cortlandt-park">Van Cortlandt Trails</a> page for a map and directions to scenic locations.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "X092",
        Name: "Putnam Trail",
        Location: "Enter the park at Van Cortlandt Park South and Bailey Avenue.",
        Park_Name: "Van Cortlandt Park",
        Length: "1.5 miles",
        Difficulty: "Easy",
        Other_Details: "This section of the 15-mile trail that runs up to Brewster, NY may be accessed by the Van Cortlandt Golf Course parking lot.  Native hardwood (oak-hickory) forest, historically significant route (former railroad route that ran through the park into the 1980s!)<br>Check out our <a href="/park-features/hiking/van-cortlandt-park">Van Cortlandt Trails</a> page for a map and directions to scenic locations.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "R120",
        Name: "Arden Woods Trail",
        Location: "Arden amp; Legate Avenue",
        Park_Name: "Arden Woods",
        Length: "1.2 miles",
        Difficulty: "Easy",
        Other_Details: nil,
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "R031",
        Name: "Wolfe's Pond Trail",
        Location: "Hylan Boulevard amp; Cornelia Avenue",
        Park_Name: "Wolfes Pond Park",
        Length: "0.75 miles",
        Difficulty: "Easy",
        Other_Details: "Both hikers and mountain bikers can explore miles of trails in this south shore location. Trails contain easy, moderate, and difficult terrain.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "R027",
        Name: "Long Pond Trail",
        Location: "Page Avenue amp; Eugene Street",
        Park_Name: "Long Pond Park",
        Length: "1.5 miles",
        Difficulty: "Easy",
        Other_Details: nil,
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "R005",
        Name: "Clove Lakes Park Trail",
        Location: "Victory Boulevard",
        Park_Name: "Clove Lakes Park",
        Length: "3.0 miles",
        Difficulty: "Easy",
        Other_Details: "Visitors can enjoy walks by its valley lakes, ascend pathways through wooded hills, pause along its picturesque bridges, or visit New York Cityamp;rsquo;s largest tulip tree.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "X039",
        Name: "Kazimiroff Trail",
        Location: "Hunter Island",
        Park_Name: "Pelham Bay Park",
        Length: nil,
        Difficulty: nil,
        Other_Details: "Leave the city far behind on the Kazimiroff Nature Trail, which provides self-guided long and short loop paths around 189-acre Hunter Island, leading visitors along the islandamp;rsquo;s wetland border, through its interior forest, and onto the shore of beautiful Orchard Beach.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "M042",
        Name: "Inwood Hill Park Hiking Trail",
        Location: "Check out our <a href="/park-features/hiking/inwood-hill-park">Inwood Hill Trails</a> page for a map featuring entrances and directions to scenic locations.",
        Park_Name: "Inwood Hill Park",
        Length: nil,
        Difficulty: "Moderate",
        Other_Details: "Take a step back in time and imagine Manhattan as a forest grove of tulip trees, oaks, and maples. Inwood Hill Parkamp;#39;s marked scenic sites or historic highlights trail will lead you to the top of the hill, where the parkamp;#39;s oldest treesamp;mdash;two Cottonwoods planted before the park was establishedamp;mdash;still live.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "X002",
        Name: "Bronx River Forest Trail",
        Location: "Enter at East Gun Hill Road for Red Trail and Burke Avenue or East 204th St. for Blue Trail",
        Park_Name: "Bronx Park",
        Length: nil,
        Difficulty: nil,
        Other_Details: "The Bronx River Forest trails offer a river respite from the busy Bronx nearby.<br>Check out our <a href="/park-features/hiking/bronx-river-forest">Bronx River Forest Trails</a> page for a map and directions to scenic locations.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "R006",
        Name: "Conference House Park Trails",
        Location: "Check out our <a href="/park-features/hiking/conference-house-park">Conference House Park Trails</a> page for a map and directions to scenic locations.",
        Park_Name: "Conference House Park",
        Length: nil,
        Difficulty: nil,
        Other_Details: "The Conference House Blue Trail extends from Shore Road and Satterlee Street all the way south to Brighton Street and Surf Avenue. Along the way, you can see a number of historic buildings, including the famed Conference House, and enjoy beautiful waterfront views of this beachside park.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "B018",
        Name: "Canarsie Park Hiking Trail",
        Location: "Check out our <a href="/park-features/hiking/canarsie-park">Canarsie Trails</a> page for a map featuring entrances and directions to scenic locations.",
        Park_Name: "Canarsie Park",
        Length: "0.5 miles",
        Difficulty: "Easy",
        Other_Details: "The Canarsie blue loop trail is just over half a mile long and circles the wetland area at the eastern side of Canarsie Park.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "Q099",
        Name: "Willow Lake Hiking Trails",
        Location: "Check out our <a href="/park-features/hiking/willow-lake">Willow Lake Trails</a> page for a map featuring entrances and directions to scenic locations.",
        Park_Name: "Alley Pond Park",
        Length: nil,
        Difficulty: "Easy",
        Other_Details: "Hikers can access the trail from the east at the Van Wyck Expressway overpass at Mauro Playground (73rd Terrace and Park Drive East) and from the west at 72nd Road and the Grand Central Parkway Service Road.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "B406",
        Name: "Paerdegat Basin Hiking Trails",
        Location: "Check out our <a href="/park-features/hiking/paerdegat-park">Paerdegat Basin Trails</a> page for a map featuring entrances and directions to scenic locations.",
        Park_Name: "Paerdegat Basin Park",
        Length: nil,
        Difficulty: "Moderate",
        Other_Details: nil,
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
    {
        Prop_ID: "Q007",
        Name: "Bayswater Park Hiking Trails",
        Location: "Check out our <a href="/park-features/hiking/bayswater-park">Bayswater Trails</a> page for a map featuring entrances and directions to scenic locations.",
        Park_Name: "Bayswater Park",
        Length: "0.25 miles",
        Difficulty: "Moderate",
        Other_Details: "From the playground of Bayswater Park, follow the painted signs on the ground into the fields. Where the Sidewalk ends, across the field a large wooden post marks the beginning of the trail.",
        Accessible: "N",
        Limited_Access: "N",
        lat: nil,
        lon: nil
    },
]
#create a Burough record for each of the 5 boroughs
    Borough.create(name: "bronx")
    Borough.create(name: "brooklyn")
    Borough.create(name: "manhattan")
    Borough.create(name: "queens")
    Borough.create(name: "staten island")

trails.each do |trail|
    case trail[:Prop_ID][0] #the first letter of the prop_id that denotes borough
    when "X"
        borough = Borough.find_by(name: "bronx")
    when "B"
        borough = Borough.find_by(name: "brooklyn")
    when "M"
        borough = Borough.find_by(name: "manhattan")
    when "Q"
        borough = Borough.find_by(name: "queens")
    when "R"
        borough = Borough.find_by(name: "staten island")
    else 
        "Error: Borough not found"
    end 
end

borough.trails.create(name: trail[:Name], location: trail[:Location], park_name: trail[:park_name], length: trail[:length], difficulty: trail[:Difficulty])

The following is the error I get when I run rake db:seed in my terminal 


 

rails прерван!
Ошибка имени: неинициализированный постоянный район
/Users/jgamez/Development/projects/javascript_project/nyc_hiking_trails/nyc_trails_api/db/seeds.rb:492: в <main>' /Users/jgamez/.rvm/gems/ruby-2.6.1/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in нагрузке’
/Users/jgamez/.rvm/gems/ruby-2.6.1/gems/bootsnap-1.5.1/lib/bootsnap/load_

 
ActiveRecord::Schema.define(version: 2020_11_26_183011) do

  create_table "api_v1_boroughs", force: :cascade do |t|
    t.string "name"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end

end
 

Комментарии:

1. Добро пожаловать в SO! Если вам нужна помощь с вашим кодом, вы должны добавить ее в вопрос. Кроме того, пожалуйста, попробуйте добавить хотя бы краткое объяснение вместо того, чтобы просто публиковать сообщение об ошибке.

2. Привет, спасибо! Как вы можете видеть, я добавил свой код, который хочу ввести в свою базу данных, но продолжаю получать сообщение об ошибке имени

3. По-прежнему недостаточно информации. У вас есть объект с именем Borough , который создается где-то за пределами этого кода? Ошибка предполагает, что это не так. Если нет, то ваш вызов Borough.create() , конечно, может не сработать.

4. Не могли бы вы показать свой файл schema.rb?

5. @JohnHanlon, я добавил свой файл schema.rb

Ответ №1:

Чтобы этот код работал:

 borough.trails.create(name: trail[:Name], location: trail[:Location], park_name: trail[:park_name], length: trail[:length], difficulty: trail[:Difficulty])
 

Вам нужно добавить все эти атрибуты в вашу схему, чтобы у значений был атрибут для хранения. Таким образом, ваша схема должна быть обновлена с помощью миграции, чтобы включить их. Пример миграции ниже:

   def change
    create_table :api_v1_boroughs do |t|
      t.string "name"
      t.string "location"
      t.string "park_name"
      t.string "length"
      t.string "difficulty"

      t.timestamps
    end
  end
 

После миграции ваша схема должна быть такой:

 ActiveRecord::Schema.define(version: 2020_11_26_183011) do

  create_table "api_v1_boroughs", force: :cascade do |t|
    t.string "name"
    t.string "location"
    t.string "park_name"
    t.string "length"
    t.string "difficulty"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end

end
 

Комментарии:

1. Если бы проблема заключалась в отсутствующем атрибуте, ошибка была бы другой

Ответ №2:

Вы должны переместить функцию create внутри цикла:

 trails.each do |trail|
    case trail[:Prop_ID][0] #the first letter of the prop_id that denotes borough
    when "X"
        borough = Borough.find_by(name: "bronx")
    when "B"
        borough = Borough.find_by(name: "brooklyn")
    when "M"
        borough = Borough.find_by(name: "manhattan")
    when "Q"
        borough = Borough.find_by(name: "queens")
    when "R"
        borough = Borough.find_by(name: "staten island")
    else 
        "Error: Borough not found"
    end 
borough.trails.create(name: trail[:Name], location: trail[:Location], park_name: trail[:park_name], length: trail[:length], difficulty: trail[:Difficulty])
end
 

Кроме этого, убедитесь, что вы создали модель района.

И, глядя на вашу миграцию, вы, вероятно, сделали что-то не так в пространстве имен модели.

Комментарии:

1. У меня есть модель для района, я попробую переместить свою функцию создания внутри цикла, спасибо!