Ive been reading quite a few guides on this and my first attempt was not successful. What I have done so far is writern n a migration for the view and got that working:
class UpcommingEvents < ActiveRecord::Migration[5.1] def up self.connection.execute %Q( CREATE OR REPLACE VIEW upcoming_events AS SELECT v.name “Venue”, to_char(e.start_date,‘Day’) “Day”, e.start_time, e.title “Event”, e.description FROM events e, venues v WHERE v.id = e.venue_id AND e.start_date BETWEEN (CURRENT_DATE -INTERVAL ‘1 day’)::date AND (CURRENT_DATE + INTERVAL ‘7 day’)::date order by start_date, v.name ) end
def down execute “DROP VIEW upcoming_events” end end
Created a controller:
class CurrentEventsController < ApplicationController def index end end
And a Model
class CurrentEvent < ApplicationRecord end
And a View
<%= notice %>
Current_Events
<% current_event.each do |ce| %> <% end %>| Venue | Day | Start Time | Event | Description | |||
|---|---|---|---|---|---|---|---|
| <%= ce.venue %> | <%= ce.day %> | <%= ce.start_time %> | <%= ce.event %> | <%= ce.description %> | |||
Bit when I add it as a route and browse to the page I get
NameError in
CurrentEvents#index
Showing /home/ben/eventpuddle/eventpuddle/rails/eventpuddle/app/views/current_events/index.html.erb where line #18 raised:
undefined local variable or method `current_event' for #<#<Class:0x007f64a41d4740>:0x007f648d40ba48>
Did you mean? current_events_index_url
Extracted source (around line **#18** ):
17
18 <% current_event.each do |ce| %>
19
20 <%= ce.venue %>
21 <%= ce.day %>
Rails.root: /home/ben/eventpuddle/eventpuddle/rails/eventpuddle
I also added to ``config/application.rb
config.active_record.schema_format = :sql
and run '``rake db:migrate db:test:prepare'
Not sure where I am going wrong;(.
``