【问题标题】:Could not find a valid mapping for nil找不到 nil 的有效映射
【发布时间】:2013-11-28 18:56:07
【问题描述】:

所以,我使用载波来允许用户上传个人资料图片。现在,最终,我希望用户能够单击图像并在 profile.html.haml 页面中即时上传新图像。

所以,我尝试在下面添加一个带有 put 操作的表单,让用户无需转到 edit.html.haml 页面即可即时更新图像。

但是,我遇到了这个错误:

Could not find a valid mapping for nil

Extracted source (around line #8):




<%= form_for(@user, :url => registration_path(@user), :html => { :method => :put }, :html => {:multipart => true}) do |f| %>
<%= link_to (image_tag current_user.profile_image_url(:thumb).to_s), edit_account_path(current_user)%>
<% end %>

我哪里做错了?

或者我试过这个可能完全关闭:

 <%= link_to (image_tag current_user.profile_image_url(:thumb).to_s), f.file_field :profile_image%>     

给出了这个错误:

Sites/Friendiose-master/app/views/home/landing_welcome.html.erb:9: syntax error, unexpected tSYMBEG, expecting ')'
...l(:thumb).to_s), f.file_field :profile_image);@output_buffer...

提前致谢。

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 devise ruby-on-rails-4 carrierwave


    【解决方案1】:

    首先,您认为这个错误可能会给我带来什么。最常见的错误:

    Sites/Friendiose-master/app/views/home/landing_welcome.html.erb:9: syntax error, unexpected tSYMBEG, expecting ')'
    ...l(:thumb).to_s), f.file_field :profile_image);@output_buffer...
    

    我不会给你完整的答案,而是教你思考如何调试它。

    https://github.com/carrierwaveuploader/carrierwave

    这是carrierwave的文档。当显示图像时,它会显示以下内容:

        <%= form_for @user, :html => {:multipart => true} do |f| %>
      <p>
        <label>My Avatar</label>
        <%= image_tag(@user.avatar_url) if @user.avatar? %>
        <%= f.file_field :avatar %>
        <%= f.hidden_field :avatar_cache %>
      </p>
    <% end %>
    

    一个提示,这不是我在讽刺,而是习惯于大量阅读和谷歌搜索。我没有使用回形针,但我可以通过 2 分钟的谷歌搜索看到问题。

    Ruby on Rails using link_to with image_tag

    这里有如何创建与图像的链接。

    从那个链接看看你的区别:

    <%= link_to (image_tag current_user.profile_image_url(:thumb).to_s), edit_account_path(current_user)%>
    

    以及正确的方法:

    <%=link_to( image_tag(participant.user.profile_pic.url(:small)), user_path(participant.user), :class=>"work") %>
    

    错误说明您缺少什么?

    立即给人们一个答案并不总是很好,而是如何解决这个问题的关键。

    【讨论】:

    • 谢谢肖恩,但它是载波而不是回形针,我应该提一下,抱歉。问题在于表格而不是 image_tag 语法。你使用团队查看器吗?
    • 您的错误在于landing_page 第9 行上的任何内容。正如它在下面的错误中所说的那样,这是image_tag
    • @SonnyBlack 如果有帮助,您可以勾选答案吗?
    猜你喜欢
    • 2020-08-22
    • 1970-01-01
    • 1970-01-01
    • 2019-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多