1

所以,我使用的载波,以允许用户上传个人资料图片。现在最终,我希望用户能够点击图片并在profile.html.haml页面上即时上传新图片。找不到有效的映射零

所以,我一直在尝试,下面添加一个形式看跌期权操作,让用户即时更新的图像,而不必去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... 

在先进的感谢。

回答

0

所以,首先,你觉得我这个错误可能。最常见的错误:

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分钟内使用Google搜索看到问题。

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") %> 

是什么错误说你失踪了?

并不总是伟大的,给人们一个答案马上但是如何计算出来的密钥。

+0

感谢肖恩,但它的载波不回形针我应该提到的是遗憾。问题出在表单不是用image_tag语法。你使用团队查看器吗? –

+0

你的错误是与任何是LANDING_PAGE线9.哪个是IMAGE_TAG因为它说,它在下面 –

+0

@SonnyBlack的错误,您可以勾选答案,如果它帮助。 –