Ruby: undefined method `<<' for nil:NilClass on model -


i have been stuck @ few days now. appreciated. keep getting nomethoderror following code:

band.rb (error apparently @booked_gigs << set.gig)

  def booked_gigs     @booked_gig = []     hired_gigs = self.bandlists.filled     hired_gigs.each |set|      if set.gig.date >= date.today       @booked_gigs << set.gig      end     end   end 

_booked.html.erb:

<% @booked.each |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 

check variable names. initialize @booked_gig = [] (singular), try add items @booked_gigs (plural).

also, want return @booked_gigs @ end of method, otherwise return contents of hired_gigs (regardless of what's inside each block)

def booked_gigs   @booked_gigs = []   hired_gigs = self.bandlists.filled   hired_gigs.each |set|     if set.gig.date >= date.today       @booked_gigs << set.gig     end   end   @booked_gigs end 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -