Working on flushing out my code for my second portfolio project at the Flatiron School. I’ve been working on this one for a while and I have definitely made huge strides in understanding restful routes and the CRUD process. One thing that I really have had to hammer in though, is what can be passed through views and redirects.
For example:
get ‘/login’ do
@duck = “quack"
if logged_in?
redirect “/projects”
else
erb :login
end
end
Here in the corresponding view, the @duck variable is valid and can be accessed is the block of code above. What I believed was, that because the variable was used and had a definition in the same block, that the variable would be passed in with the redirect. However, when you redirect to a new route it is like a new instance.
I believe my biggest hindrance to understanding this was the use of helpers in my case the session.
For example:
get '/projects/:project_project_name' do
if Helpers.is_logged_in?(session)
@user = Helpers.current_user(session)
@project = Helpers.current_project(session)
erb :'projects/projects'
else
redirect '/login'
end
end
The session is passed to the “erb :'projects/projects':” because this is not a redirect to a route but instead is requesting the project.erb file in the projects folder under the views.













