I’ve got an issue where Rails is for some reason redirecting the new and edit methods to the home page, but the index and show methods are returned fine.
There is nothing special in the controller, or the routes, though I’ll include them below.
The error I’m getting is
Started GET "/recipes/new" for 192.168.5.46 at 2011-11-07 11:40:06 -0800 Processing by RecipesController#new as HTML Creating scope :page. Overwriting existing method Recipe.page. SQL (4.0ms) SHOW TABLES Creating scope :page. Overwriting existing method User.page. SQL (3.5ms) SHOW TABLES User Load (1.1ms) SELECT `users`.* FROM `users` WHERE (`users`.`id` = 2) LIMIT 1 CACHE (0.1ms) SELECT `users`.* FROM `users` WHERE (`users`.`id` = 2) LIMIT 1 Creating scope :page. Overwriting existing method RoleUser.page. Creating scope :page. Overwriting existing method Role.page. Role Load (2.5ms) SELECT `roles`.* FROM `roles` INNER JOIN `role_users` ON `roles`.id = `role_users`.role_id WHERE ((`role_users`.user_id = 2)) Completed in 887ms Redirected to http://localhost:3000
I’m assuming the problem is with this ‘overwriting’ bit, but I don’t know why it is attempting to do that, and then redirecting to home.
my recipes controller is
class RecipesController < ApplicationController
load_and_authorize_resource
before_filter :require_user
respond_to :html, :js
def index
@recipes = Recipe.find_all_by_author_id(current_user.id)
end
def show
@recipe = Recipe.find(params[:id])
end
def new
return render :text =< 'new recipe'
@recipe = Recipe.new
end
def create
@recipe = Recipe.new(params[:recipe])
@recipe.author_id=current_user.id
if @recipe.save
flash[:notice] = "Successfully created recipe."
redirect_to @recipe
else
render :action =< 'new'
end
end
end
even the render text on new isn’t returning, it goes right to the redirect.
Any ideas why this might be happening and suggestions to resolve it?
What in method
:require_user?If you comment
load_and_authorize_resourceis it work?