Open Mirv opened 7 years ago
No thats not by design, thats purely an error on my end. Would it be best to go through and add the filter onto each controller? Although maybe we want to allow access to some parts of the application without logging in? such as; recipes page and workouts page?
That's a user design question - I've seen those ones where you can see the preview of the receipes & then when you click it's like "BAM SIGN UP TO SEE FOR FREE!". It would be relatively easy to add the "before_filter" action to the application_controller", then insert except for ":index" and ":show" on each individual controller you want to permit the ones you want?
Sorry didn't mean to close this one @jatwell93
I think i've fixed this up, i've gone through each of the controllers and added the devise filter for the relevant actions. I wasn't quite sure what you meant by the "before_filter" for the application controller though?
the before filter is beforeaction or ... doing something and filtering in the controllers is all it means really, sometimes I drop the "" in there to emphasize something & I shouldn't :)
While we're on the topic, should this;
class RecipesController < ApplicationController
include RecipesHelper
before_action :set_user, except: [:index, :new]
be to this?
class RecipesController < ApplicationController
include RecipesHelper
before_action :set_user, except: [:index, :show, :new]
so users can view the recipes show page without logging in? Currently this generates the error undefined method
id' for nil:NilClass`, when a non-logged in user tries to view a recipe
However adding :show causes an error with the current helper
I think this is a situation of separate concerns... set_user exists to get the current_user and apply it for making changes - this should not be required or related to index. Also, you are telling me in this post anyone whether they are signed in (identified) or not should see the page.
3 things to try
First, add that set_user & see if it fixes Second, it could be that record doesn't exist for real in the db, verify it via the rails console & do Recipe.find(x) Third, it's an extra on the webpage....start removing chunks of code & adding them back after you find working version
You've got a ton of controllers and not all of them have the devise authentication check ... is this by design? So people can read the site without logging in?
It came up because in many of your pages you are relying on "current_user" but you don't have a "current_user" if not logged in (or if you don't provision some special invisible default guest access user) ...
@jatwell93