The error I am getting is:
SyntaxError in PagesController#main
C:/Users/Sarah/RubymineProjects/MyApp/app/views/calendars/_show.html.erb:49: syntax error, unexpected ')', expecting keyword_then or ';' or '\n' ...=( if event.starts_at.monday? );@output_buffer.safe_append=' ... ^ C:/Users/Sarah/RubymineProjects/MyApp/app/views/calendars/_show.html.erb:52: syntax error, unexpected keyword_end, expecting ')' '.freeze; end ^ C:/Users/Sarah/RubymineProjects/MyApp/app/views/calendars/_show.html.erb:54: syntax error, unexpected keyword_end, expecting ')' '.freeze; end ^ C:/Users/Sarah/RubymineProjects/MyApp/app/views/calendars/_show.html.erb:364: syntax error, unexpected keyword_ensure, expecting ')' C:/Users/Sarah/RubymineProjects/MyApp/app/views/calendars/_show.html.erb:366: syntax error, unexpected keyword_end, expecting ')'
but the code I'm trying to write is:
<% @events.each do |event|%>
<%= if event.starts_at.monday? %>
<p><%= event.name %></p>
<% end %>
<% end %>
Is this really because of my syntax (which I think seems fine) or is it a problem with my code somewhere? I am writing this code in _show.html.erb (from calendars controller) which is a partial that is being rendered in my main.html.erb (from Pages controller)
this is the code I'm using to render my partial:
<%= render partial: '/calendars/show', locals: {} %>
and here are my controllers and models:
class PagesController < ApplicationController
#before_action :require_customer, only: [:main]
def home
end
def main
@events = current_customer.calendar.events
end
end
my calendar controller:
class CalendarsController < ApplicationController
def new
@calendar = Calendar.new(calendar_params)
end
def create
@calendar = Calendar.new(calendar_params)
end
private
def calendar_params
params.require(:customer_id)
end
def show
@calendar = current_customer.calendar
@events = @calendar.events
end
end
my events controller (just for reference)
class EventsController < ApplicationController
before_filter :logged_in?
def new
@event = Event.new
@calendar = current_customer.calendar
end
def create
@calendar = current_customer.calendar
@event = @calendar.events.build(event_params)
if @event.save
redirect_to '/main' #'/main/#{@calendar.id}'
else
redirect_to '/compose'
end
end
private
def event_params
params.require(:event).permit(:calendar_id, :name, :starts_at, :ends_at)
end
also here are my calendar and events models:
class Calendar < ActiveRecord::Base
belongs_to :customer
has_many :events
end
class Event < ActiveRecord::Base
belongs_to :calendar
end
I've been stuck on this for days I just can't seem to find an explanation. Thanks!
Aucun commentaire:
Enregistrer un commentaire