I am getting NoMethodError in Rooms#index, specifically undefined method `boolean_array_from_amenities_integer' for #. I defined "boolean_array_from_amenities_integer" in the Room.rb model however I am not picking it up. Any help would be appreciated.
room.rb
class Room < ActiveRecord::Base
validates :amenities, presence: true
def self.amenities_list
["Smoking Allowed",
"Pets Allowed",
"TV",
"Cable TV",
"Internet",
"Wireless Internet",
"Air Conditioning",
"Heating",
"Elevator in Building",
"Handicap Accessible",
"Pool",
"Kitchen",
"Free parking on premise",
"Doorman",
"Gym",
"Hot Tub",
"Indoor Fireplace",
"Buzzer/Wireless Intercom",
"Breakfast",
"Family/Kid Friendly",
"Suitable for Events",
"Washer",
"Dryer"]
end
def boolean_array_from_amenities_integer
[].tap do |amenities_list|
Room.amenities_list.length do |order|
amenities_list << (self.amenities & 2 ** order > 0)
end
end
end
end
rooms_conroller.rb
class RoomsController < ApplicationController
before_filter :require_current_user!, only: [:new, :create]
def index
@room = Room.all
end
def show
@room = Room.find(params[:id])
end
def new
@room = Room.new
end
def create
@room = Room.new(params[:room])
@room.set_amenities_from_options_list!(params[:room_amenities_indicies])
if @room.save
redirect_to @room
else
flash.now[:errors] = @room.errors if @room.errors
render :new
end
end
private
def room_params params.require(:room).permit(:amenities, :amenities_indices) end end
new.html.erb
<label for="room-amenities" class="top">Amenities</label>
<ul class="group" id="room-amenities">
<% Room.amenities_list.each_with_index do |amenity, index| %>
<li class="checkbox-li">
<input type="checkbox" name="room_amenities_indicies[]" value="<%= index %>">
<%= amenity %>
</input>
</li>
<% end %>
</ul><br>
<input type="submit" class="button blue input-large label-offset-button" value="Create room">
</form>
index.html.erb
<label for="amenities-tab-button">Amenities</label>
<div class="tab-content group">
<% amenities_list = Room.amenities_list %>
<ul>
<% @room.boolean_array_from_amenities_integer.each_with_index do |amenity_available,index| %>
<% if amenity_available %>
<li class="available-amenity">
<% else %>
<li class="unavailable-amenity">
<% end %>
<%= amenities_list[index] %>
</li>
<% end %>
</ul>
</div>