Rails - 标签链接的简单形式,不可点击

时间:2018-03-24 11:39:14

标签: ruby-on-rails simple-form simple-form-for

我已经为自己的政策制定了自定义标签'复选框。在这个标签中,我创建了一个链接,我想将其设置为用户同意的策略。现在我已经将root链接设置为测试。

该复选框是可点击的。然而,自定义标签中的链接不是<?p?

形式:

 <div id="signup">
      <h2>Sign up</h2>
      <%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
        <div class="form-inputs">
          <%= f.input :email, required: true, autofocus: true, placeholder: "Email", label: false %>
          <%= f.input :first_name, required: true, autofocus: true, placeholder: "First name", label: false %>
          <%= f.input :last_name, autofocus: true, placeholder: "Last name", label: false %>
          <%= f.input :password, required: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length), placeholder: "Password", label: false %>
          <%= f.input :password_confirmation, required: true, placeholder: "Confirm password", label: false %>
          <%= f.input :agree_with_policy, as: :boolean, boolean_style: :inline, label: ("I agree to the #{link_to 'Terms of Service', root_path}.").html_safe %>
        </div>
      <div class="form-actions">
        <%= f.button :submit, "Sign up" %>
      </div>
      <% end %>
    </div>

在呈现的HTML下面:

<div id="signup" style="display: block;">
      <h2>Sign up</h2>
      <form novalidate="novalidate" class="simple_form new_user" id="new_user" action="/users" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="✓"><input type="hidden" name="authenticity_token" value="yagrA8LqprToyfLLZkpfvJ8NALBngVshr9g4MdmqzhfQnaCFpRkfWko3YTVq9f6cyFX5ePqGXa5iAPS4aL2WsQ==">
        <div class="form-inputs">
          <div class="form-group email required user_email"><input class="form-control string email required" autofocus="autofocus" required="required" aria-required="true" placeholder="Email" type="email" value="" name="user[email]" id="user_email"></div>
          <div class="form-group string required user_first_name"><input class="form-control string required" autofocus="autofocus" required="required" aria-required="true" placeholder="First name" type="text" name="user[first_name]" id="user_first_name"></div>
          <div class="form-group string required user_last_name"><input class="form-control string required" autofocus="autofocus" placeholder="Last name" type="text" name="user[last_name]" id="user_last_name"></div>
          <div class="form-group password required user_password"><input class="form-control password required" required="required" aria-required="true" placeholder="Password" type="password" name="user[password]" id="user_password"></div>
          <div class="form-group password required user_password_confirmation"><input class="form-control password required" required="required" aria-required="true" placeholder="Confirm password" type="password" name="user[password_confirmation]" id="user_password_confirmation"></div>
          <div class="form-group boolean required user_agree_with_policy"><div class="checkbox"><input name="user[agree_with_policy]" type="hidden" value="0"><input class="boolean required" type="checkbox" value="1" name="user[agree_with_policy]" id="user_agree_with_policy"><label class="boolean required" for="user_agree_with_policy"><abbr title="required">*</abbr> I agree to the <a href="/terms-of-service">Terms of Service</a> and the <a href="/privacy-policy">Privacy Policy</a>.</label></div></div>
        </div>
      <div class="form-actions">
        <input type="submit" name="commit" value="Sign up" class="btn" data-disable-with="Sign up">
      </div>

1 个答案:

答案 0 :(得分:2)

而不是通过设置false简单形式在label: false set <label></label>中添加标签,而不是为此特定字段创建标签,而是我们可以自己创建。然后创建一个普通的html <label for="resource_agree_with_policy">I agree to the <%= link_to 'Terms of Service', root_path %></label> <%= f.input :agree_with_policy, as: :boolean, boolean_style: :inline, label: false %> ,当它呈现时,它的行为也与当前视图相同。更新将如下:

label: false

注意:您可以根据样式更新HTML标记。这里需要了解的重要事项是f.input :agree_with_policy中的public LinkedList<Object[][]> addMatrices() { LinkedList<Object[][]> l=new LinkedList<>(); Object[][] o=new Object[2][2]; o[0][0]=new Empty(2); o[0][1]=new Other(); o[1][0]=new Empty(4); o[1][1]=new Empty(6); l.add(o); Object[][] o2=new Object[2][2]; o2[0][0]=new Empty(4); o2[0][1]=new Other(); o2[1][0]=new Empty(5); o2[1][1]=new Empty(1); l.add(o2); for(Object[][] oo:l) { for(int x=0;x<oo.length;x++){ for(int y=0;y<oo[x].length;y++) { System.out.print("\t"+oo[x][y]+" "); System.out.print("\t|");} System.out.println(System.lineSeparator()); } System.out.println(System.lineSeparator()); } return l; }