私はRailsの初心者です。私はUdemyのRails開発者コースに参加しています。 /search_stocks
ルートに移動しようとすると、次のエラーが発生します。Ruby on Rails - 未定義メソッド `split 'for nil:StocksController#searchのNilClass/NoMethodError
ここで(私も下の貼り付けコードを持っている)現在の状態でレポです: https://github.com/udemyrailscourse/finance-tracker
TAコースのことを示唆している:https://github.com/sarahbasinger/rails-stock-tracker
はここUdemyコースレポです宝石版の競合である可能性があります。私はRails 5.1.4を使用しています(初心者の間違いかもしれません - 最新かつ最高のものを使うことは良い方法だと思いました)。コースの教師はRails 4を使用しています。TAは私がコースと同じ宝石のバージョンを使用することを提案しました。コースGemfile、ランバンドルのインストールに合わせてGemfileを更新しました。実行するサーバー。私は別のエラーを取得します。だから私はRails 5を使ってこのアプリを動かそうとしています。しかし、それが問題であれば、宝石のバージョンの競合を解決しようとする経験はありません。
モデル
class Stock < ActiveRecord::Base
def self.new_from_lookup(ticker_symbol)
looked_up_stock = StockQuote::Stock.quote(ticker_symbol)
new(name: looked_up_stock.name, ticker: looked_up_stock.symbol, last_price: looked_up_stock.l)
end
end
コントローラ
class StocksController < ApplicationController
def search
@stock = Stock.new_from_lookup(params[:stock])
render json: @stock
end
end
ビュー
0:はここに関連するコードです
Gemfile
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.4'
gem 'devise'
gem 'twitter-bootstrap-rails'
gem 'jquery-rails'
gem 'devise-bootstrap-views'
gem 'stock_quote'
# Use Puma as the app server
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
gem 'sqlite3'
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '~> 2.13'
gem 'selenium-webdriver'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :production do
gem 'pg'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
すべてのヘルプは歓迎です!
これを助けるために
モデル
希望は私の問題に対する正しい答えです。大きな時間をfacepalmの瞬間...私は間違ったルートを開始していた。私がする必要があったのは、検索入力を持つ/ my_portfolioから始めることでした。それから私が検索を押すと、/ search_stocksに私を送り、URL paramsを通して入力値を渡します。 100%正常に動作しています。 https://stock-tracker-app-sb.herokuapp.com/my_portfolio(非常に恥ずかしい)。こんにちは@ joaquin-rocaと、これを調べる時間をとってくれたばかだ。あなたの答えは、私が間違っていたことを理解するようになりました。 – Sarah
私の喜び。私は助けることができてうれしい! –