我已经在这个上面呆了几天了。 任何帮助将不胜感激。 对于以下代码,我不断收到此 nomethoderror :
band.rb(错误显然是@booked_gigs <<set.gig)
def booked_gigs
@booked_gig = []
hired_gigs = self.bandlists.filled
hired_gigs.each do |set|
if set.gig.date >= Date.today
@booked_gigs << set.gig
end
end
end
_booked.html.erb:
<% @booked.each do |booked| %>
<%= render "shared/gig_full", gig: booked %>
<% end %>
dashboard_controller.rb:
class DashboardController < ApplicationController
before_filter :authenticate_user!, only: [:dashboard]
def dashboard
if current_user.role == "venue"
set_venue_dash
render "venue_dashboard"
elsif current_user.role == "musician"
set_band_dash
if @band.nil?
redirect_to new_band_path
else
set_band_session
set_booked_gig
set_applied_gig
render "band_dashboard"
end
else
set_fan_dash
render "fan_dashboard"
end
end
def settings
end
private
def set_venue_dash
@venue = current_user.venues.first
end
def set_band_dash
@band = current_user.bands.first
end
def set_band_session
session[:current_band_id] ||= @band.id
@openings = @band.available_gigs
end
def set_booked_gig
@booked = current_band.booked_gigs
end
def set_applied_gig
@applied = current_band.applied_gigs
end
def set_fan_dash
@fan = current_user.fan
end
end
检查变量名称。初始化@booked_gig = []
(单数),但随后尝试将项添加到@booked_gigs
(复数)。
此外,您可能希望在方法末尾返回@booked_gigs
,否则它将返回hired_gigs
的内容(无论您的each
块中的内容如何)
def booked_gigs
@booked_gigs = []
hired_gigs = self.bandlists.filled
hired_gigs.each do |set|
if set.gig.date >= Date.today
@booked_gigs << set.gig
end
end
@booked_gigs
end