ruby-on-rails - Ruby Tokbox API 中 nil:NilClass 的未定义方法“用户”
问题描述
我正在尝试使用 tokbox api,但出现以下错误:
Started GET "/en/stream" for 127.0.0.1 at 2018-06-02 18:38:57 +0800
Processing by UsersController#stream as HTML
Parameters: {"locale"=>"en"}
Rendering users/stream.html.erb within layouts/application
Rendered users/stream.html.erb within layouts/application (3.8ms)
Completed 500 Internal Server Error in 34ms (ActiveRecord: 0.3ms)
ActionView::Template::Error (undefined method `user' for nil:NilClass):
1: <%= javascript_include_tag "//static.opentok.com/webrtc/v2.2/js/TB.min.js" %>
2: <h1>Your stream</h1>
3: <div id="publisher"></div>
4: Link to your stream: <%= link_to watch_url(@stream.user.id), watch_url(@stream.user.id) %>
app/views/users/stream.html.erb:4:in `_app_views_users_stream_html_erb__3447765015494674598_70186549432640'
我的 User/stream.html.erb 看起来像:
<%= javascript_include_tag "//static.opentok.com/webrtc/v2.2/js/TB.min.js" %>
<h1>Your stream</h1>
<div id="publisher"></div>
Link to your stream: <%= link_to watch_url(@stream.user.id), watch_url(@stream.user.id) %>
我的用户控制器看起来像:
def stream
@stream = User.find(params[:id]).stream
@stream = current_user.stream || current_user.create_stream
gon.opentok = opentok_data(@stream)
end
def watch
@stream = User.find(params[:id]).stream
gon.opentok = opentok_data(@stream)
end
private
def opentok_data(stream)
token = OpenTokClient.generate_token(stream.opentok_session_id)
{ sessionId: stream.opentok_session_id, apiKey: Figaro.env.opentok_api_key, token: token }
end
我的用户模型有一个流,我的流模型有一个用户。有谁知道为什么它不识别用户?
解决方案
推荐阅读
- javascript - 难以将正则表达式与过滤方法匹配
- jquery - 将选定选项从多个选择标签推送到数组中
- python - 如何使用 Python 将每个月的常数乘以原始时间序列
- python - 如何将此函数映射到 pyspark
- vue.js - Vue - 将道具传递给计算
- java - Spring Boot 2 静态资源子文件夹
- visual-studio-code - 可以在 Emmet 自动完成上更改类标签名称吗?
- r - ggplot2热图没有从高到低排列值
- gnuplot - brew install gnuplot --with-qt --with-x11 不工作
- typescript - Typescript 中的泛型函数图