Why is my index view not working when I implement datepicker in my rails app
- by user3736107
Hi I am new to rails and would really appreciate some help, I am using the jQuery datepicker, the show view works however the index view doesn't, i get "undefined method `start_date' for nil:NilClass" in my index.html.erb file. Can you please let me know what is wrong with my index view and how i can fix it. The following are included in my app:
meetups_controller.rb
def show
@meetup = Meetup.find(params[:id])
end
def index
@meetups = Meetup.where('user_id = ?', current_user.id).order('created_at DESC')
end
show.html.erb
<h3>Title: <%= @meetup.title %></h3>
<p>Start date: <%= @meetup.start_date.strftime("%B %e, %Y") %></p>
<p>Start time: <%= @meetup.start_time.strftime("%l:%M %P") %></p>
<p>End date: <%= @meetup.end_date.strftime("%B %e, %Y") %></p>
<p>End time: <%= @meetup.end_time.strftime("%l:%M %P") %></p>
index.html.erb
<% if @meetups.any? %>
<% @meetups.each do |meetup| %>
<h3><%= link_to meetup.title, meetup_path(meetup) %></h3>
<p>Start date: <%= meetup.start_date.strftime("%B %e, %Y") %></p>
<p>Start time: <%= meetup.start_time.strftime("%l:%M %P") %></p>
<p>End date: <%= @meetup.end_date.strftime("%B %e, %Y") %></p>
<p>End time: <%= @meetup.end_time.strftime("%l:%M %P") %></p>