Tough finding a subject line that’s fitting.
Anyway , I have a REST controller with a model called Cdetail.
I am only allowing 1 record per user for this table and want the app
to redirect with a flash message if they’ve already inserted one.
So here is my new method:
@cdetail = Cdetail.new # Don’t think I actually need this here
@uid = current_user.id
and here is the create method:
if Cdetail.find_by_user_id(@uid) == true flash[:notice] = "Allowed only one record" redirect_to(:controller => 'index', :action => 'index') end @cdetail = Cdetail.new(params[:cdetail]) @cdetail.save!
I’m a newb so trying to remember what I’ve learned as I go along
(still going back to book)
but I expect the if statement if it finds a record for the
current_user in the method (column) user_id it would redirect away
from the create method, however it’s not doing so. It’s not throwing
an error either but …
I suppose this is what happens when a Ruby N. jumps to quickly into
Some direction or advice would be greatly appreciated.