2013-06-26 47 views
0

我知道資源只能嵌套一次,但我有兩個模型嵌入三重嵌套水域,這使得事情比他們需要的更復雜,但我沒有看到方式,以避免它在這兩種情況下......這樣:表單不顯示爲三重嵌套資源

嵌套是這樣的:組>導航欄>鏈接

我有出現鏈接形式問題呈現:

- simple_form_for new_group_navbar_link_path(@group, @navbar, @link) do |f| 
    %fieldset.well.pleft80.edit 
    = f.input :method_name 
    = f.input :text 
    = f.input :button 

    .form-actions 
    = f.submit nil, :class => 'btn btn-primary pull-right btn-large' 

navbar belongs_to groups and link belongs_to navbar 

控制器: 類LinksController <的ApplicationController 的before_filter:fetch_group 的before_filter:fetch_navbar 的before_filter:fetch_link,只有:[:顯示,編輯,:更新:摧毀]

def show 
    end 

    def new 
    @link = Link.new 
    end 

    def create 
    @link = @navbar.links.build(params[:link]) 

    if @link.save 
     redirect_to @navbar, notice: 'link was successfully updated.' 
    else 
    render :new 
    end 
end 

def edit 
    @image = @link.build_image unless @link.image 
end 

    def update 
    respond_to do |format| 
     if @link.update_attributes(params[:link]) 
     format.html { redirect_to @navbar, notice: 'link was successfully updated.' } 
     format.json { head :no_content } 
     else 
     format.html { render action: "edit" } 
     format.json { render json: @link.errors, status: :unprocessable_entity } 
    end 
    end 
    end 

    def destroy 
    @link.destroy 
    redirect_to navbar_path(@navbar) 
    end 

    private 

    def fetch_group 
    @group = Group.find(params[:group_id]) 
    end 
    def fetch_navbar 
    @navbar = Navbar.find(params[:navbar_id]) 
    end 
    def fetch_link 
    @link = @navbar.links.find(params[:id]) 
    end 
end 

有一些簡單的我俯瞰?

回答

1

只是

= simple_form_for new_group_navbar_link_path(@group, @navbar, @link) do |f| 
+1

哈更換

- simple_form_for new_group_navbar_link_path(@group, @navbar, @link) do |f| 

。也許我只是有點累了。謝謝! –