BookmkfoldersController中的SyntaxError #index,未知的regexp选项 - dv

时间:2017-08-15 16:17:32

标签: javascript ruby-on-rails ruby

我想制作一个Web应用程序,到目前为止一切正常。但是,ActionView突然出错了。它似乎无法识别关闭的html标签。每当它看到一个封闭的括号时,它声称这些是未公开的。但是,我认为他们都是!我已经在下面发布了错误日志,可能有人知道发生了什么......!

我收到以下错误:

 SyntaxError in BookmkfoldersController#index
 app/views/bookmkfolders/index.html.erb:16: unknown regexp options - dv
 app/views/bookmkfolders/index.html.erb:17: syntax error, unexpected '<'

这是文件index.html.erb

<ul class="board-canvas" data-update-url = "<%=sort_bookmkfolders_url %>">

 <% @bookmkfolders.each do |bookmkfolder| %>
      <div class="panel-wrapped">
          <li id="<%=bookmkfolder.id%>" class="panel" style = "background-color:<%=bookmkfolder.bookmkfoldercolor%>">
            <%= text_field_tag :test, "", class: 'thVal' %>
            <h2 class= "panel-title" ><%= bookmkfolder.bookmkfoldertitle %></h2>
            <div class="panel-menu">
              <%= button_tag "Add a bookmark-url", type: 'button', class: 'addfolder js-add-card' %>
              <div class="add-card-form">
                <%= simple_form_for @bookmkfolder, remote: true, url: {action: "<%= @bookmkfolder.id %>"} do |k| %>
                <%= k.input_field :bookmktitle, class: 'board-make-input', autocomplete: :off, autocorrect: :off, spellcheck: false, placeholder: 'Add a bookmark' %>
                <%= button_tag "SAVE", type: 'submit' , class: 'save-button js-save-card' %>
                <%= button_tag "", type: 'button', class: 'delete-button' , "<span class="fa fa-times fa-1x" aria-hidden="true"></span>".html_safe %>
                <% end %>
              </div>   # this is error message app/views/bookmkfolders/index.html.erb:16
            </div>
          </li>

          <ul class="card-list">
            <% bookmkfolder.@bookmks.each do |bookmk| %>
              <li class ="card-item">
                <%= link_to "","<%= bookmk.bookmktitle %>", class: 'card-link' %>
                <%= image_tag "#", class: 'card-thumbnail' %>
                <p class = "card-txt"><%= bookmk.bookmktitle%></p>
              </li>
            <%end%>
          </ul>
      </div>
 <%end%>
</ul>

这是从bookmkfolders_controller提取的来源。

def index
 @bookmkfolders = Bookmkfolder.all
 @bookmkfolders = Bookmkfolder.order("sequence")
 @bookmkfolder = Bookmkfolder.new
 @bookmks = Bookmk.all
 @bookmk = Bookmk.new
end

def newfolder

 #  redirect_to '/bookmkfolder/createfolder'
end

def createfolder
 colors = ['#c9ddff', '#c9ffdd', '#ffd2c9', '#c9caff', '#fdc9ff', '#fffdc9', 
 '#c9fffc', '#ffc9c9', '#ffe5c9', '#eaffc9']
  puts Bookmkfolder.methods
  @bookmkfolder = Bookmkfolder.new(bookmkfolder_params)
  @bookmkfolder.user = current_user
  @bookmkfolder.sequence = Bookmkfolder.count + 1
  @bookmkfolder.bookmkfoldercolor = colors.at(rand(colors.size))

  respond_to do |format|
    if @bookmkfolder.save
      format.html { redirect_to @bookmkfolder, notice: 'Bookmkfolder was 
successfully created.' }
      format.js {}
      format.json { render :show, status: :created, location: @bookmkfolder }

    else
      format.html { render :new }
      format.json { render json: @bookmkfolder.errors, status: 
   :unprocessable_entity }
    end
  end
end

2 个答案:

答案 0 :(得分:0)

我认为这是错误的:

<%= button_tag "", type: 'button', class: 'delete-button' , "<span class="fa fa-times fa-1x" aria-hidden="true"></span>".html_safe %>

您试图以奇怪的方式附上"<span class="fa fa-times fa-1x" aria-hidden="true"></span>"

这应该有效:

'<span class="fa fa-times fa-1x" aria-hidden="true"></span>'

(我将开头和结尾替换为'with')

答案 1 :(得分:0)

你不能像这样嵌套<% %>

<%= simple_form_for @bookmkfolder, remote: true, url: {action: "<%= @bookmkfolder.id %>"} do |k| %>

一旦你打开<%你正在使用Ruby,所以你可以只使用代码中的变量,如下所示:

<%= simple_form_for @bookmkfolder, remote: true, url: { action: @bookmkfolder.id } do |k| %>

与当前错误无关,但也注意到第二个button_tag不正确(除了使用嵌套的双引号),您无法传递类似于尝试使用"<span>...</span>".html_safe的参数

您要找的是传递,如下所示:

<div class="add-card-form">
  <%= button_tag "", type: 'button', class: 'delete-button' do %>
    <span class="fa fa-times fa-1x" aria-hidden="true"></span>
  <% end %>
</div>

您可以在the docs中了解button_tag