Brian McDonough
Brian McDonough

Reputation: 14479

form not appearing for triple nested resource

I know that resources should only be nested once, but I have two models that dip into the triple nested waters, which makes things more complex than they need to be, but I do not see a way to avoid it in these two cases...so:

The nesting works like this: group>navbar>links

I am having issues getting the link form to render:

- 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

Controller: class LinksController < ApplicationController before_filter :fetch_group before_filter :fetch_navbar before_filter :fetch_link, only: [:show, :edit, :update, :destroy]

  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

Is there something simple I'm overlooking?

Upvotes: 0

Views: 274

Answers (1)

maximus ツ
maximus ツ

Reputation: 8065

just replace

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

with

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

Upvotes: 1

Related Questions