我遇到了一个奇怪的问题.
undefined method `values' for #<ActionController::Parameters:0x007fb06f6b2728>
Run Code Online (Sandbox Code Playgroud)
是我得到的错误,当我将变量分配给param哈希,并尝试获取它的值.
attributes = params[:line_item][:line_item_attributes_attributes] || {}
attributes.values
Run Code Online (Sandbox Code Playgroud)
该参数看起来像哈希的散列:
{"0"=>{"product_attribute_id"=>"4"}, "1"=>{"product_attribute_id"=>"7"}}
Run Code Online (Sandbox Code Playgroud)
现在,当我在控制台中执行此操作并将其分配给变量属性时,它可以完美地工作.所以我很难理解这里没有的东西 - 以及如何让它发挥作用.
我在Rails应用程序上设置了一个websocket,并且能够从同一台服务器上连接和接收数据.
我现在的方法是创建一个这样的套接字:
class UsersChannel < ApplicationCable::Channel
def subscribed
stream_from "users_1"
end
def unsubscribed
end
end
Run Code Online (Sandbox Code Playgroud)
然后我用javascript打开连接
new WebSocket('wss://domain.com/cable/users_1');
然后我以这种格式从页面广播和发送JSON:
ActionCable.server.broadcast "users_1", {
store: {
name: store.name,
address: {
full_address: location.address,
latitude: location.latitude,
longitude: location.longitude
}
}
Run Code Online (Sandbox Code Playgroud)
当触发时我可以在我的控制台中看到它出现.我在JS中添加了这个频道:
App.cable.subscriptions.create "UsersChannel",
received: (data) ->
console.log data
Run Code Online (Sandbox Code Playgroud)
现在我们正在使用React Native构建应用程序,当我们将此代码添加到我们的应用程序时:
var ws = new WebSocket('wss://domain.com/cable/users_1');
ws.onmessage = (e) => {
console.log(e.data);
};
Run Code Online (Sandbox Code Playgroud)
我们看到它ping,但是当我们触发广播时什么都没收到.我还将其添加到配置文件中:
config.action_cable.url = 'wss://domain.com/cable'
config.action_cable.disable_request_forgery_protection = true
Run Code Online (Sandbox Code Playgroud)
谁知道为什么会这样?
所以我正在努力设置我的 Flash 消息。目前我的 _messages 看起来像这样:
<% flash.each do |message_type, message| %>
<%= content_tag(:div, message, class: "alert alert-#{message_type}", role: "alert") %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
但是随着设计他们继续使用警报通知。其中通过 bootstrap 显然没有连接到它的颜色。如何将设备默认值更改为选定的 4 个之一?
嘿,我正在尝试创建一个心跳,告诉我客户何时完成会话.
我的控制器看起来像这样:
def update
@customer = Customer.find(params[:id])
@room = Room.find(params[:room_id])
@customer.charge(@room)
@customer.update_attribute(finished_at: DateTime.now)
session[:customer_id] = nil
respond_to do |format|
format.js
format.htmt { redirect_to root_url }
end
end
Run Code Online (Sandbox Code Playgroud)
现在在我的show.html.erb文件中我有这个:
setInterval(function(){
$.post("/customers/<%= current_customer.id %>", {finished_at: date.now()}, function(){});
}, 5000);
Run Code Online (Sandbox Code Playgroud)
现在,当我检查我的控制台时,我得到的错误是:
Uncaught ReferenceError: date is not defined
Run Code Online (Sandbox Code Playgroud)
这里可能有一些错误,有谁知道什么事了?
我正在想办法解决这个问题。
假设我有 10 张图片,每张图片都是 95x95 - 然后我创建一个高度为 300px、宽度为 100% 的容器(相对位置)。
现在我想拍摄这 10 张照片(绝对位置)并将它们随机放置在容器中top和left容器内,但我不想让它们彼此重叠。
我创建图片标签
for (let person of people) {
let personBubble = document.createElement('a')
personBubble.style.backgroundImage = "url(" + person.picture_url + ")";
personBubble.style.display = 'block';
personBubble.style.width = '100%';
personBubble.style.height = '100%';
personBubble.style.backgroundSize = '100% 100%';
personBubble.style.position = 'absolute';
personBubble.style.top = '0';
personBubble.style.left = '0';
personBubble.style.borderRadius = '50%';
personBubble.style.zIndex = '10';
}
Run Code Online (Sandbox Code Playgroud)
现在基本上我想以这样的方式更改顶部和左侧属性,以便可以解决这个问题(而不是让所有 10 个属性都位于顶部 0 和左侧 0)