简体   繁体   中英

Rails method is returning a span tag instead of a string for my placeholder

I have a translation method that takes a string and returns another based on the user. It returns the string for all of my buttons and links but keeps returning a span tag when I try to use it with placeholders. I'm also using Twitter Bootstrap, not sure if that matters.

The translation method:

  def translator(english)
    # takes string and searches Translation.all for a match unless user.english
    unless current_user.english
      spanish = Translation.where(english: english)
    end
    return spanish.present? ? spanish.last.spanish : english
  end

My search bar with the placeholder:

<%= form_tag search_path, :method => "get" do %>
    <div class="input-group">
        <%= text_field_tag :query, params[:query],
            placeholder: translate("Search"), class: "form-control" %>
        <span class="input-group-btn">
            <button class="btn btn-default" type="submit">
                <i class="glyphicon glyphicon-search"></i>
            </button>
        </span>
    </div><!-- /input-group -->
<% end %>

The tag being produced. It's saying translation missing even when I know there's a match. From view-source:

placeholder="<span class="translation_missing" title="translation missing: en.Search">Search</span>"

您已经定义了一种称为“ translator的方法,但是您正在调用一种名为“ translate的方法:您正在调用rails translation helper,而不是您定义的方法。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM