问题描述
当结束时意外结束,但我看不出问题出在哪里。 我的终端不断给我错误:ActionView::SyntaxErrorInTemplate(渲染模板时遇到语法错误:
我的 profile.html.erb
<% if @users.image.present? %>
<%= image_tag @users.image %>
<% end %>
<strong><h1><%= @users.full_name %></h1></strong>
<% if user_signed_in? %>
<% if @user == current_user %>
<%= link_to"Edit Profile",edit_user_registration_path(@user) %>
<% if user_signed_in? && !@user? %>
<% if current_user.following?(@user) %>
<%= link_to"Unfollow",follows_path(user_id: @user.id),method: :delete %>
<% else %>
<%= link_to"Follow",follows_path(user_id: @user.id) %>
<% end %>
<% end %>
<% end %>
<% end %>
<div> <%= @users.posts.count %> Posts </div>
<p><%= @users.full_name %></p>
<p><%= @users.description %></p>
<p><%= link_to @users.website if @users.website.present? %></p>
<%= @posts.each do |post|%>
<%= image_tag post.image %>
<% end %>
解决方法
问题似乎在这里
<p><%= link_to @users.website if @users.website.present? %></p>
改成
<p><%= link_to 'User Website',@users.website if @users.website.present? %></p>
,
<% if user_signed_in? && @user == current_user %>
<%= link_to"Edit Profile",edit_user_registration_path(@user) %>
<% if current_user.following?(@user) %>
<%= link_to"Unfollow",follows_path(user_id: @user.id),method: :delete %>
<% else %>
<%= link_to"Follow",follows_path(user_id: @user.id) %>
<% end %>
<% end %>
现在好了:D
,我看到了两个错误,请纠正。首先,没有什么 @user?
是最大的错误,另一个可能不是问题,但没有空间 <%= link_to"Edit Profile"
请尝试以下代码,我已更改内容并正确重新格式化。
<% if @users.image.present? %>
<%= image_tag @users.image %>
<% end %>
<strong><h1><%= @users.full_name %></h1></strong>
<% if user_signed_in? %>
<% if @user == current_user %>
<%= link_to "Edit Profile",edit_user_registration_path(@user) %>
<% if user_signed_in? && !@user %>
<% if current_user.following?(@user) %>
<%= link_to"Unfollow",method: :delete %>
<% else %>
<%= link_to"Follow",follows_path(user_id: @user.id) %>
<% end %>
<% end %>
<% end %>
<% end %>
<div> <%= @users.posts.count %> Posts </div>
<p><%= @users.full_name %></p>
<p><%= @users.description %></p>
<p><%= link_to @users.website if @users.website.present? %></p>
<%= @posts.each do |post|%>
<%= image_tag post.image %>
<% end %>