I am trying to connect my pages so that the user has a show page and once they get to the show page they see events. The Event can also be clicked on and once that event is clicked on it goes directly to that events show page. The error I am getting is
No route matches {:action=>"show", :controller=>"events", :id=>nil}
Here is what my events form looks like:
<span class="name">EventName: <%= link_to(event.name, controller: "events", action: "show", id: @event) %></span>
<span class="partycode">PartyCode:<br><%= event.partycode %></span>
Here is my Events controller:
class EventsController < ApplicationController
def show
@event = Event.find(params[:id])
end
def create
@event = current_user.events.build(event_params)
if @event.save
flash[:success] = "Event Created!"
redirect_to root_url
else
render 'welcome#index'
end
end
def destroy
end
private
def event_params
params.require(:event).permit(:name, :partycode)
end
end
Let me know if you need more code to figure out the problem my error occurs in the events form on the first line. This has been really frustrating because this should be a simple task.
Try changing
to
(note the missing @) in your template.