Travel Places

Hello! I started working on Rails already but I'm back in Sinatra to do the final project as I don't want to get further ahead. This is fun! I am enjoying working on how to make a real world Sinatra application. Following the suggestions given, I am trying to make something that I would like to use. I have a notebook of places I would like to visit and things I would like to do in those places so I am building an app to replicate and store this information online. I am hewing closely to the golf club example given as I was having a little trouble getting started, some blank slate hesitancy. But I'm glad I dove in and this makes sense as a way not only to think through the concepts but also see how they interrelate via shotgun. I hope to move further from the golf club example as I grasp the whole picture here thoroughly. I copied the golf club example to my computer and pushed to github and deleted most of the files to start fresh. Making lots of commits!

CSS - I plan to come back to styling CSS at the end. I started working on some styling because I thought some rainbow text might enliven things up but I wasn't getting it to display with Shotgun. I think it's because of the links in my views layout page which I copied over from the golf club example overriding the CSS page I built. Will return to this later.   


Application Controller: 

We are requiring our environment.rb file and the ApplicationController class inherits from Sinatra::Base. In the configure block I am enabling sessions and generating a session_id with these lines: 

configure do
enable :sessions
set :session_secret, "travelspots"

Then a Sinatra get method to erb: index to render views/index.erb. In Rails we work on seperate helper files. Here we have a helpers method to display an error message if someone hasn't logged in. Setting up a user_id key in the session hash for later use. I am researching other ways to verify login here.


So far I have an Index view file that just has welcome html and a more extensive layout view. Curious how these two files relate in priority. It seems that the layout view is above or before the index view. The application controller renders the index view. How does the layout view know to display?

In the body of the HTML on the layout page we have a nav bar. The nav bar has Sign Up and Sign In links (directing links  <a href="/signup"> to users/new.erb which creates a formand <a href="/login"> to users/login.erb which also creates a form). Where does it know to look in the views/users folder? How does it know /signup refers to users/new.erb? The users controller! If we are already logged in <% if logged_in? %> we have two different links in the nav bar. <a href="/activity/new"> to create a new activity or <a href="/logout">  to logout. I quit and restarted Shotgun to see that we're still in the same login session. 

I need to study up on routes! The golf bag example gets a little further into sinatra routes than I feel completely comfortable with. I understand the if/else statements and using redirect to. I need a little help making sure I comprehend the pairs of get and post methods. For instance, in my users_controller.rb file, I have a get '/login' and a post '/login'. 

I've added some user views. Hoping to test the site with shotgun but my signup and login links are still broken. I might need to add view folders for locations and activities first? Might be why they are breaking. I am going to put up my app and what I have thus far but I am still working on it and do not consider it complete.