In trying to set-up policies for my practice app. I'm running into a "No Method Error" in my posts controller.
If we zero in on the post controller and my update method here is the code.
def update
authorize @post
respond_to do |format|
if @post.update(post_params)
format.html { redirect_to @post, notice: 'Post was successfully updated.' }
format.json { head :no_content }
#redirect_to @post
else
render :edit
format.html { render action: 'edit' }
format.json { render json: @post.errors, status: :unprocessable_entity }
end
end
end
As you can see nothing really special. Just a HTML and JSON rendering of the updated page.
The authorize
code points to a helper in pundit that looks up the access policies.
Defined in my Admin.rb model i have.
def editor?
self.role == 'editor'
end
The authorize
code looks up the policy that corresponds to the method name. It looks in the policy class and starts applying the business rules found here. And here is where the problems start.
I get to def update?
@admin.editor?
end
And it says undefined method 'editor?' for #<Class:0x007ffb7fa4f6a0>
The code is on the policy branch on Git : https://github.com/wmuengineer/portfolio/tree/policy