未定义的局部变量或方法“ meta_title”

时间:2019-09-02 15:05:38

标签: ruby-on-rails meta-title

尝试为网站设置一些meta_title标签,我似乎遇到了错误。几次检查我的文件后,我没有看到错误。发现任何帮助将不胜感激

我认为这可能是某个地方的拼写错误,但我没有看到它。我还认为这可能是因为自从我弄乱配置文件以来,我需要重新启动本地服务器,但这也无法解决我的错误

config / meta.yml

<div style="overflow-x:auto; width:90%; margin: 0 auto" id="Group16882">
    <div class="caption">
        <br>Instructions <!-- br should be self closing-->
    </div>

    <table border="1" width="100%" align="center" cellpadding="2" cellspacing="1" 
          summary="Instruction" class="generaltable" style="position:static">
        <tr>
            <td valign="top" colspan="1" rowspan="2" class="edit">
               <span style="font-size: 20; color:blue; " id=C ol197626> <!-- id is not in quotes-->
                 <b>
                     The 50 States, District of Columbia, and the
                      Commonwealth of Puerto Rico and other 
                       territories a Modernizas report is not 
                       considered to be confidential.
                   <br> <!-- should be self closing-->
                 </b>
               </span>
            </td>
        </tr>
    </table>
</div>

<div style="overflow-x:auto; width:90%; margin: 0 auto" id="Group16883">
    <div class="caption"></div>

    <table border="1" width="100%" align="center" cellpadding="2" cellspacing="1" 
            summary="Estimated Figures" class="generaltable" style="position:static">
        <tr>
            <td valign="top" colspan="2" rowspan="1" class="edit">
                <span id=C ol197627> <!-- id is not in quotes where is the close of span-->
                    <b>
                        </a> Click <!-- this is a end and should be a start also you have double wrapoped the a which should not be done. (anchor anchor double anchor does not make much sense)-->

                           <a ref="http://www.acf.hhs.gov/programs/ocs/resource/funding- 
                              applications" target="_blank">HERE</a>
                            to read the expandctions.
                            <br><br>
                        <A> <!-- should be lower case and should be an end, see above-->
                </b>
           </td>
        </tr>

       <tr>
          <td valign="top"  colspan = "1" rowspan = "1" width = "74%" class="edit">
            <span id = Col197628> <!-- id is not in quotes  where is the close of span-->
               <b>
                  </A> <!-- should be lower case, a start not an end-->
                       Do the data below  figures?<br>
                      If YEpf assistance that has 
                      at least one estimated data entry.
                   <A> <!-- should be lower case should be a end and not a start-->
               </b>
          </td>

          <td valign="top"  colspan = "1" rowspan = "1" width = "26%" class="edit">
            <span id = Col197629> <!-- id is not in quotes-->
                <b>
                    </A>Select One<A> <!-- tag start and end switched-->
                    <br>
                </b>
                &nbsp;

                <img src="file:/C:/apache-tomcat-8.5.24/webapps/oldcwb/WEB-INF/classes/acf/oldc/ws/images/radiounchecked.gif"  alt="No">

                &nbsp;Yes&nbsp;&nbsp;&nbsp;

                <img src="file:/C:/apache-tomcat-8.5.24/webapps/oldcwb/WEB-INF/classes/acf/oldc/ws/images/radiounchecked.gif"  alt="No">

                &nbsp;No&nbsp;&nbsp;
            </span>
          </td>
        </tr>
    </table>
</div>

config / initializers / default_meta.rb

meta_product_name: "A PRODUCT NAME I HAVE REMOVED"
meta_title: "A PRODUCT DESCRIPTION OF SIMILAR LENGTH TO THIS"
meta_description: "A description of fair length to describe the above"
meta_image: "image.png" 
twitter_account: "@someone"

app / helpers / meta_tags_helper.rb

DEFAULT_META = YAML.load_file(Rails.root.join("config/meta.yml"))

app / controllers / application_controller.rb

module MetaTagsHelper
  def meta_title
    content_for?(:meta_title) ? content_for(:meta_title) : DEFAULT_META["meta_title"]
  end

  def meta_description
    content_for?(:meta_description) ? content_for(:meta_description) : DEFAULT_META["meta_description"]
  end

  def meta_image
    meta_image = (content_for?(:meta_image) ? content_for(:meta_image) : DEFAULT_META["meta_image"])
    # little twist to make it work equally with an asset or a url
    meta_image.starts_with?("http") ? meta_image : image_url(meta_image)
  end
end

app / views / layouts / application.html.erb

  def default_url_options
    { host: ENV["DOMAIN"] || "localhost:3000" }
  end

鉴于上述情况,我希望页面能够加载,并且当我尝试在FB等上共享页面时,图像和Blur都是我自己设计的。我在localhost上遇到的所有错误是未定义的meta_title错误

2 个答案:

答案 0 :(得分:0)

我不确定这是阻止页面加载的一个问题,但这是自发布此问题以来我唯一碰过的事情:

名称.b后面的meta_tags_helper.rb文件可能有多余的空格。我打开了重命名选项卡,删除了一个空格并保存。现在该程序可以工作了。我无法理解为什么这么小的更改在这里实际上很重要。

答案 1 :(得分:0)

我对助手的了解达到了3或4。

我确实必须将帮助程序包含在控制器中,如我所希望的那样,在这样的范围内:

# for instance, in application_controller.rb
include MetaTagsHelper

我希望现在不应该有所不同。