- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在为 RoR 站点编写聊天页面。我已经在 HTML 中完成了所有工作,并且我正在尝试使用 ajax 来实现它。有一个用于提交消息的表格。表单标签显示为 <%= form_for(@chat, remote: true, :authenticity_token => true) do |f| %>
我的整体观点:
<!DOCTYPE html>
<html>
<head>
<title>Battleriskopoloy - Communications</title>
</head>
<body>
<br>
<div id="heading_1" align="center">
<br><span id="title"><strong>[ . . . Communications . . . ]</strong></span>
</div><br>
<div id="sidebar"><br>
<% $chat_users.each do |user| %>
<% user = User.find_by_username(user) %>
<%= button_to user.username, flop_chat_path(user), :class => "select", :method => :get %>
<% end %>
</div>
<div id="display">
<% $messeges.each do |i| %>
<% if i[1] == "from" %>
<p style="color:#000000; text-align:right; margin-right:5%;font-family:courier"><%= i[0] %></p>
<br>
<% else %>
<p style="color:#FF0000; text-align:left; margin-left:5%; font-family:courier"><%= i[0] %></p>
<br>
<%end%>
<%end%>
</div>
<div id="textfield">
<%= form_for(@chat, remote: true, :authenticity_token => true) do |f| %>
<%= f.text_field :content, id: "compose" %>
<br>
<br>
<%= f.submit "Send Messege", id: "submit" %>
<% end %>
</div>
</body>
</html>
Controller :
class ChatsController < ApplicationController
$messeges = Array.new(10, " ")
def new
$messeges = Array.new
if $ruser != nil
$messeges = Array.new
Chat.all.each_with_index do |i, index|
if i.recipient == current_user.id && i.sender == $ruser.id
$messeges.push([i.content, "to"])
end
if i.recipient == $ruser.id && i.sender == current_user.id
$messeges.push([i.content, "from"])
end
end
end
$chat_users = Array.new
User.all.each do |user|
if user != nil && current_user != nil
if user.game_id == current_user.game_id && user.id != current_user.id
$chat_users.push(user.username)
end
end
end
@chat = Chat.new
end
def create
if $ruser != nil
@chat = Chat.new(chat_params)
@chat.recipient = $ruser.id
@chat.sender = current_user.id
@chat.save
end
redirect_to "/comms/new"
end
def flop
$ruser = User.find(params[:id])
$messeges = Array.new
Chat.all.each_with_index do |i, index|
if i.recipient == current_user.id && i.sender == $ruser.id
$messeges.push([i.content, "to"])
end
if i.recipient == $ruser.id && i.sender == current_user.id
$messeges.push([i.content, "from"])
end
end
redirect_to "/comms/new"
end
private
def chat_params
params.require(:chat).permit(:content)
end
end
另外,我有 <%= csrf_meta_tags %>
在我的 application.html.erb 中
我在网上发现了一些关于人们在从 ajax 切换到 html 提交时遇到与 rails 4 相同的错误的其他事情,但这似乎只是因为他们没有 :authenticity_token => true
包括参数。非常感谢任何帮助。
最佳答案
默认情况下 authenticity_token
设置为 false
。所以你需要在你的 application.rb
config.action_view.embed_authenticity_token_in_remote_forms = true
关于ruby-on-rails - 使用带有 remote: true 的 ajax 的 Ruby 表单会给出 ActionController::InvalidAuthenticityToken 错误。经典提交不,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24319353/
这个问题在这里已经有了答案: Why in Python does "0, 0 == (0, 0)" equal "(0, False)"? (7 个回答) 去年关闭。 代码片段 1: a = Tru
Integer i = 127; Integer j = 127; System.out.println(i == j); System.out.println(i.equals(j)); Integ
我试图用 Python 进行类似下面的代码的比较,但对产生的输出感到困惑。 谁能解释为什么输出是这样的? >>> True, True == True, True (True, True, True)
我们的下拉值是动态的 010100。 你能帮我将这些值转换为 true、false 吗? Offer的值是10100,Reject的值是10111。所以这些需要转换成 10100 = true,fal
我正在测试,如果用户在页面顶部显示一种货币“EUR”和另一种货币“GBP”,那么我期望包含文本“EUR”和页面下方还存在另一个包含文本“GBP”的链接。它包含在一个名为 "nav-tabs au-ta
如何检查数组的所有元素是真值还是假值。 因为以下内容似乎没有做到这一点:_.all([true, true, true], true); 它返回:false? 最佳答案 您应该重新阅读_.every(
C#:我有一个如下所示的字符串变量: string a = "(true and true) or (true or false)"; 这可以是任何东西,它可以变得更复杂,比如: string b
ruby : true == true == true syntax error, unexpected tEQ 对比JavaScript: true == true == true // => tr
这个问题已经有答案了: Equality of truthy and falsy values (JavaScript) (3 个回答) Which equals operator (== vs ==
为什么 R 中的 TRUE == "TRUE" 是 TRUE? R 中是否有与 === 等效的内容? 更新: 这些都返回FALSE: TRUE == "True" TRUE == "true" TRU
简单的查询,可能不可能,但我知道那里有一些聪明的人:) 给定一个 bool 参数,我希望定义我的 where 子句来限制特定列的输出 - 或不执行任何操作。 因此,给定参数@bit = 1,结果将是:
编写 Excel 公式时,将值设置为 true、“true”还是 true() 是否有区别? 换句话来说,以下哪一个是最好的?还是要看具体情况? if (A1 = 1, true, false) if
如果我们评估这个:TRUE AND TRUE,为什么会这样? 'yes' : 'no' 等于 TRUE 但不等于 yes 何时评估:(TRUE AND TRUE) ? 'yes' : 'no' 等于
这个问题在这里已经有了答案: Behaviour of and operator in javascript [duplicate] (1 个回答) 关闭 7 年前。 如题所说,我不太明白为什么(t
我有一个包含 FromDate 、 ToDate 、 VendorName 和 GoodsName 的表单,一旦一切为真,我需要显示结果 示例: FromDate="11/20/2019"、ToDat
我最近参加了 Java 的入门测试,这个问题让我很困惑。完整的问题是: boolean b1 = true; boolean b2 = false; if (b2 != b1 != b2) S
我有一个模型,我有: ipv4_address = models.IPAddressField(verbose_name=_('ipv4 address'), blank=True, null=Tru
False in [True,True] False in pd.Series([True,True]) 第一行代码返回False第二行代码返回 True! 我想我一定是做错了什么或者遗漏了什么。当我
我可以在 Coq 中证明以下内容吗? Lemma bool_uip (H1 : true = true): H1 = eq_refl true. 即true = true 的所有证明都相同吗? 例如
如果我的理解是正确的,他们做的事情完全一样。为什么有人会使用“for”变体?仅仅是味道吗? 编辑:我想我也在考虑 for (;;)。 最佳答案 for (;;) 通常用于防止编译器警告: while(
我是一名优秀的程序员,十分优秀!