【问题标题】:syntax error, unexpected ')', expecting keyword_then or ';' or '\n'语法错误,意外的 ')',需要 keyword_then 或 ';'或'\n'
【发布时间】:2014-01-10 14:15:56
【问题描述】:

此错误与什么有关?我不知道代码不正确的地方?

用户 索引.html.erb

<%= @events.all.each do |event| %>
  <%= if current_user.activities.include?(event.activity) %>
    <%= event.activity %>
    <%= event.description %>
    <%= event.start_time %>
    <%= event.end_time %>
    <%= event.num_attendees_requested %>
    <%= event.location_name %>
    <%= event.street_address %>
    <%= event.city %>
    <%= event.state %>
  <% end %>
<% end %>

用户控制器

class UsersController < ApplicationController
  def index
    @users = User.all
    @activities = Activity.all
    @events = Event.all
  end

  def show
    @user = current_user
    @events = Event.all
    @activities = Activity.all
  end

【问题讨论】:

  • 您应该在@events.all.each do |event| 之前使用&lt;% 而不是&lt;%=,但这不会帮助您解决语法错误。您应该发布错误回溯。

标签: ruby-on-rails views controllers


【解决方案1】:
<%= if current_user.activities.include?(event.activity) %>

<% if current_user.activities.include?(event.activity) %>

【讨论】:

  • 没关系,&lt;%= @events ... %&gt;&lt;% @events ... %&gt; 在第一行也是如此。
猜你喜欢
  • 1970-01-01
  • 2019-12-09
  • 2022-02-25
  • 1970-01-01
  • 2021-03-10
  • 2012-01-14
  • 1970-01-01
  • 2011-11-07
相关资源
最近更新 更多