小编CHa*_*ris的帖子

Ruby on Rails如果......其他

我有以下代码:

<div class="category_name">
     <%= current_user %>
     <%= review.user.front_name %>
      <% if current_user.name = review.user.front_name %>
      <%= link_to "You", user_path(review.user) %> / <%= review.categories_list %>
      <% else %>
      <%= link_to review.user.front_name, user_path(review.user) %> / <%= review.categories_list %>
      <% end %>
    </div>
Run Code Online (Sandbox Code Playgroud)

它呈现如下:

Tom Murphy Bill Smith你/电影

为什么会这样?

<% if current_user.name = review.user.front_name %>
Run Code Online (Sandbox Code Playgroud)

换句话说,如果汤姆墨菲=比尔史密斯......它没有...它不应该在'其他'之后走线?这就是我想要发生的事情.

if-statement ruby-on-rails

1
推荐指数
1
解决办法
143
查看次数

为什么我的JSON数组没有以正确的格式返回?

当我回应$json2JSON Array的回归时:

[{"contact_phonenumber":"12345"}][{"contact_phonenumber":"67890"}][{"contact_phonenumber":"123456"}][{"contact_phonenumber":"78901"}][{"contact_phonenumber":"234567"}][{"contact_phonenumber":"8901234"}]
Run Code Online (Sandbox Code Playgroud)

它看起来不像JSON Array我,我确定我的循环有问题 - 也许是因为while它嵌套在for each或者什么东西,但即使我改变它,我仍然得到相同的结果.你能帮我吗?

我想要它JSON array像:

[{"contact_phonenumber":"12345"}, {"contact_phonenumber":"67890"},
 {"contact_phonenumber":"123456"}, {"contact_phonenumber":"78901"},{"contact_phonenumber":"234567"}, {"contact_phonenumber":"8901234"}]
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

<?php

require('dbConnect.php');

//this is the username in the user table
$Number = "+353872934480";

// get the username of the user in the user table, then get the matching user_id in the user table
// so we can check contacts against it 
$query = "SELECT * FROM user WHERE username = ?";
$stmt …
Run Code Online (Sandbox Code Playgroud)

php while-loop

1
推荐指数
1
解决办法
88
查看次数

带有字符串[]数组的android for循环

我可以让个体stringsstring [] array这样的例子:

//first, make stringArray1 the same size as arrayList1
stringArray1 = new String[arrayList1.size()];

//stringArray1 will contain all the values in arrayList1
stringArray1 = arraylist1.toArray(stringArray1);

//for each value in stringArray1 make it into an individual string,
//called string1
            for(String string1: stringArray1 )

            {
                System.out.println("string1 is " + string1);

             }
Run Code Online (Sandbox Code Playgroud)

你能告诉我如何将另一个字符串转换string [] array放入同一个for循环中吗?这两个arrayList1arrayList2是完全一样的大小。我以为我可以使用&&但没有快乐。我得到'Expression expected'。还是我需要有两个不同的for循环?这就是我所拥有的:

//first, make stringArray1 the same size as arrayList1 …
Run Code Online (Sandbox Code Playgroud)

android for-loop

1
推荐指数
1
解决办法
1万
查看次数

如何使javascript文件可以访问ruby变量?

我有两个变量,<%= @user.lat %><%= @user.lng %>

这些变量根据登录我系统的用户而变化 - 这是用户在注册我的应用程序时提供的地址.

scripts.js我一直在尝试定义它们的文件中,因此我的Google地图可以显示用户的纬度和经度.

function initialize_google_maps() {
    var currentlatlng = new google.maps.LatLng(<%= @user.lat %>, <%= @user.lng %>);
Run Code Online (Sandbox Code Playgroud)

等,等不起作用,因为它无法理解我的ruby代码.

我尝试在scripts.js文件的顶部定义它们,如:

var map_latitude = "<%= @user.lat %>";
var map_longitude = "<%= @user.lng %>";
Run Code Online (Sandbox Code Playgroud)

然后使用:

  function initialize_google_maps() {
    var currentlatlng = new google.maps.LatLng(map_latitude, map_longitude);
Run Code Online (Sandbox Code Playgroud)

但我知道你不能把ruby放在js文件中.我确实尝试将其重命名为scripts.js.erb,但这也无效.

那么,我该如何定义<%= @user.lat %>,<%= @user.lng %>所以我们的scripts.js文件会识别它们,并显示在我的地图中?我在这里尝试了这个答案,创造了一个局部,但它对我不起作用.也许我做错了.

请注意:我不能简单地将代码和映射函数放在html.erb文件中的脚本标记之间,因为我使用了一些ajax,而且事情搞砸了 - 红宝石变量需要被js文件识别.谢谢.

javascript ruby ruby-on-rails

0
推荐指数
1
解决办法
3624
查看次数

如何修复意外的JSON异常org.json.指数超出范围

为什么我会收到此错误,如何解决?我在我的43项ListView,其中index 4338来自哪里?

我在这里查看了解决方案:JSONArray例外:索引50超出范围[0..50).是否对JsonArray有任何限制并相应地修改我的代码但仍然得到错误.

这些错误最终出现logcat- 我的ListView负载最终在大约20秒之后似乎太长了 - 但只有在重复数百次后在Logcat中显示此错误之后 - 索引3829一直到4338(沿途跳过一些) .

这是我的代码:

public class PopulistoListView extends AppCompatActivity {

    // this is the php file name where to select from.
    // we will post the user's phone number into Php and get the matching user_id
    private static final String SelectUserReviews_URL = "http://www.example.com/SelectUserReviews.php";

    //we are posting phoneNoofUser, the key is phonenumberofuser, which we see in php
    public static final String KEY_PHONENUMBER_USER = "phonenumberofuser"; …
Run Code Online (Sandbox Code Playgroud)

android json listview

0
推荐指数
1
解决办法
456
查看次数