我有一个.html.erb文件,它应该在某个参数为“true”时打印一条消息,而在另一个参数为“false”时打印一条消息。这是文件的代码:
<%= if params[:result] == "true" %>
<h1>Success</h1>
<p>The words <%=params[:first] %> and <%= params[:second] %> are anagrams! <br>
<%= else %>
<h1>Oh no!</h1>
<p>The words <%=params[:first] %> and <%= params[:second] %> are not anagrams. <br>
<br>
<%= link_to 'Try another pair', welcome_index_path%>
但是我收到了这个错误:
/home/mariana/Documents/RD-anagram/anagram/app/views/solver/result.html.erb:3: syntax error, unexpected ')', expecting keyword_then or ';' or '\n' if @result == "true" );@output_buffer.safe_append='
/home/mariana/Documents/RD-anagram/anagram/app/views/solver/result.html.erb:6: syntax error, unexpected keyword_else '.freeze;@output_buffer.append=( else );@output_buffer.safe_append='
/home/mariana/Documents/RD-anagram/anagram/app/views/solver/result.html.erb:11: syntax error, unexpected keyword_ensure, expecting ')'
/home/mariana/Documents/RD-anagram/anagram/app/views/solver/result.html.erb:13: syntax error, unexpected keyword_end, expecting ')'
答案 0 :(得分:5)
if语句应该是这样的。正在删除&lt;%= if%&gt;到&lt;%if%&gt;应该工作。
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfCustomControlLibrary1">
<DataTemplate x:Key="ItemTemplate_List">
<TextBlock Text="{Binding Text}" HorizontalAlignment="Left"/>
</DataTemplate>
<DataTemplate x:Key="ItemTemplate_ListCheck">
<Grid>
<CheckBox IsChecked="{Binding IsChecked}"/>
<TextBlock Text="{Binding Text}" Margin="20,0,0,0" HorizontalAlignment="Left"/>
</Grid>
</DataTemplate>
<Style TargetType="{x:Type local:MyListView}">
<Style.Triggers>
<Trigger Property="Mode" Value="List">
<Setter Property="ItemTemplate" Value="{StaticResource ItemTemplate_List}"/>
</Trigger>
<Trigger Property="Mode" Value="ListCheck">
<Setter Property="ItemTemplate" Value="{StaticResource ItemTemplate_ListCheck}"/>
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
答案 1 :(得分:-1)
复制以下代码
<% if params[:result] %>
<h1>Success</h1>
<p>The words <%=params[:first] %> and <%= params[:second] %> are anagrams! <br>
<%else %>
<h1>Oh no!</h1>
<p>The words <%=params[:first] %> and <%= params[:second] %> are not anagrams. <br>
<%end%>