小编Spa*_*nce的帖子

使用本地主机应用程序的 iframe

我有一个 Rails 应用程序页面,我想将其用作不同网页上的 iframe。我的 rails 应用程序的一部分是new我的score对象的视图。目前我的 rails 应用程序只是在本地托管。为了测试我的 iframe,我在publicRails 应用程序的文件夹中有一个 HTML 页面。

这是test.html页面

<html>

<iframe width="400" height="400" src="scores/new?site_id=191">

</iframe>

</html>
Run Code Online (Sandbox Code Playgroud)

但是,这不起作用。这是我检查 iframe 时得到的错误

GET file:///Users/spencerhanson/Documents/Projects/net-promoter-score/public/scores/new?site_id=191 net::ERR_FILE_NOT_FOUND

我知道 public/scores/new/.. 不是我的项目中存在的地方。我不明白为什么它试图看那里。该test.html文件在/public/目录中。这里的事情是,我以前有过这个工作,src在我的 iframe 中使用相同的标签。我没有改变任何东西,然后有一天 iframe 停止在我的测试页面上工作。我无法弄清楚出了什么问题。我知道这可能src是我的 iframe的标签,因为我试图在一个也是本地的页面上显示本地托管的站点

html iframe ruby-on-rails

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

JavaScript 循环内的 HTML

我正在尝试创建 10 个单选按钮,在 html 中用 for 循环标记为 1-10,但无法使其工作。

<html>
    <body>
      <h2 style="text-align:center">
        On a scale from 1-10, how likely are you to recommend this site to a friend or colleague?
      </h2>
        <form id="NPSform"; style= "text-align:center">
            <script>
                for (var i = 1; i <=10; i++) {
                    <input type="radio" name="scores" id="i" value="i"> i
                }
            </script>
            <input type="submit" name="mysubmit" value="Submit"/>
        </form>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

谢谢。我是 JS 新手,所以我还在学习很多东西。

html javascript

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

使用JavaScript获取提交单选按钮值

我在这里有这个非常基本的HTML,我最终会变成一个iframe,它基本上只是一个简单的小部件,在用户端获得分数,然后我希望它将数据发送回我的rails后端.现在,我正试图找出当用户检查按钮并点击提交时如何获得分数.

<html>
<head>
</head>
<body>
  <h1 style="text-align:center">Net Promoter Score!</h1>
  <form id="NPSform"; style= "text-align:center">

    <input type="radio" name="scores" id="1" value="1"> 1
    <input type="radio" name="scores" id="2" value="2"> 2
    <input type="radio" name="scores" id="3" value="3"> 3
    <input type="radio" name="scores" id="4" value="4"> 4
    <input type="radio" name="scores" id="5" value="5"> 5
    <input type="radio" name="scores" id="6" value="6"> 6
    <input type="radio" name="scores" id="7" value="7"> 7
    <input type="radio" name="scores" id="8" value="8"> 8
    <input type="radio" name="scores" id="9" value="9"> 9
    <input type="radio" name="scores" id="10" value="10"> 10
    <input type="submit" name="mysubmit" value="Submit"/>
</form>
</body>


<script> …
Run Code Online (Sandbox Code Playgroud)

html javascript ruby-on-rails

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

Java中的StringIndexOutOfBounds

我在这里有两个完全相同的代码副本,除了一个在for循环中有'<'而另一个有'<='.有人可以解释为什么当我使用'<='时我会得到索引超出范围的异常,但是它可以正常使用'<'

错误代码:

for(int i = 0; i <= str.length(); i++) {
      int count = 0;
      char currentChar = str.charAt(i);
      for(int j = 0; j <= str.length(); j++) {
        if (currentChar == str.charAt(j) ) {
          count++;
Run Code Online (Sandbox Code Playgroud)


工作代码:

for(int i = 0; i < str.length(); i++) {
      int count = 0;
      char currentChar = str.charAt(i);
      for(int j = 0; j < str.length(); j++) {
        if (currentChar == str.charAt(j) ) {
          count++;
Run Code Online (Sandbox Code Playgroud)


如果我不使用<=它将如何比较字符串中的最后一个字符?

java string character operators

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

Rails验证两个字段之一(XOR)的存在

如何验证是否存在这些值之一,但不能同时存在?

  validates_presence_of :client_id, message: 'Please enter a value'
  validates_presence_of :agency_id, message: 'Please enter a value'
Run Code Online (Sandbox Code Playgroud)

我查看了rails指南,我认为我需要使用条件验证,但仍然有些困难。

ruby-on-rails

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

使用水豚点击基于 ID 的链接

我在表中有两行,每行都有一个我想用 Capybara 测试的“预览”按钮,但我正在努力弄清楚如何单独单击每个预览按钮。我是 Capybara 的新手,所以我仍在学习。这是桌子的样子

<tr>
    <td>
        <a data-target="#1_edit_prompt" data-toggle="modal" href="#">Cta 1</a>
    </td>
    <td class="nowrap">
    Cta 1
    </td>
    <td class="nowrap">
        <a data-target="#1_uses_modal" data-toggle="modal" href="#">0</a>
    </td>
    <td class="nowrap">
    3/9/2017
    </td>
    <td class="actions">
        <a data-target="#1_edit_prompt" data-toggle="modal" href="#">Edit</a>
        <a data-target="#1_delete_modal" data-toggle="modal" href="#">Delete</a>
        <a class="cta-preview" data-cta_id="1" href="#">Preview</a>
    </td>
</tr>
<tr>
    <td>
        <a data-target="#2_edit_prompt" data-toggle="modal" href="#">Cta 2</a>
    </td>
    <td class="nowrap">
        Cta 2
    </td>
    <td class="nowrap">
        <a data-target="#2_uses_modal" data-toggle="modal" href="#">0</a>
    </td>
    <td class="nowrap">
        3/9/2017
    </td>
    <td class="actions">
        <a data-target="#2_edit_prompt" data-toggle="modal" href="#">Edit</a>
        <a data-target="#2_delete_modal" data-toggle="modal" href="#">Delete</a>
        <a …
Run Code Online (Sandbox Code Playgroud)

html rspec ruby-on-rails capybara

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

Rails 将 id 传递给 rspec 测试

嘿,我正在尝试使用 rspec 测试我的new操作,但遇到了一些麻烦。

这是new我的scores_controllerA 分数的操作,该操作也将与某个网站相关联。一个site has_many scoresscore belongs_to一个site

def new
    @score = Score.new(site: Site.find(params['site_id']))
  end
Run Code Online (Sandbox Code Playgroud)

这是我目前的 rspec 测试:

describe 'new' do
    with :user
    with :score
    with :site
    before do
      sign_in user
      get :new, id: site.id
    end
    it { expect(response).to have_http_status :ok }
    it { should render_template :new }
    it 'assigns a new score as @score' do
      expect(assigns(:score)).to be_a_new(Score)
    end
  end
Run Code Online (Sandbox Code Playgroud)

这是我收到的错误

1) ScoresController new
     Failure/Error: @score = Score.new(site: Site.find(params['site_id'])) …
Run Code Online (Sandbox Code Playgroud)

ruby rspec ruby-on-rails

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