2011-11-07 9 views
0

我有一個問題,其中Rails是由於某種原因將新的和編輯方法重定向到主頁,但索引和顯示方法返回正常。新的和編輯控制器操作重定向到家,'覆蓋現有的方法'

控制器或路線沒有什麼特別之處,儘管我會在下面包含它們。

我得到的錯誤是

 
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 

我假設的問題是這個「覆蓋」一點,但我不知道爲什麼它正試圖做到這一點,然後重定向到家。

我的食譜控制器

 
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 

即使是在新的沒有返回渲染文本,它會正確的重定向。

任何想法,爲什麼會發生這種情況,並提出解決它的建議?

回答

1

什麼在方法:require_user
如果您的意見load_and_authorize_resource是否有效?

+0

當然!謝謝,我不相信我沒有看到。現在我只需要弄清楚爲什麼自動化不適用於該頁面。似乎錯誤是使用cancan的授權。謝謝 – pedalpete

相關問題