0

trying to wrap my head round something and hoping someone can help.

I have a loop as follows to dislay a list of assets (images) for a property:

- @property.property_assets.each do |asset|

Each asset has an image with a description field, ie:

= asset.description

This works perfectly fine.

I'd like to have a form for each asset so I can update the description, with a submit.

My form_for currently looks like:

= form_for asset , url: property_property_assets_path do |f|

My routes file:

resources :properties do 

    resources :property_assets

    member do
      post :update_general
      post :update_promo_image
      post :update_location

    end
end

My property_assets_controller:

def index
    @property = Property.find(params[:property_id])
end

def update

    if @property_asset.update(property_asset_params)
      respond_to do |format|
        format.html
        format.js
        flash[:notice] = "Updated property asset"
      end
    else
      render 'edit'
    end
  end

The issue

I'm getting the error:

No route matches {:action=>"index", :controller=>"property_assets", :id=>"1"} missing required keys: [:property_id]

Thanks in advance

1
  • Try giving it like this = form_for asset , url: property_property_assets_path(@property) do |f| Commented May 29, 2014 at 8:53

1 Answer 1

1

You should have:

= form_for [@property, asset] do |f|
Sign up to request clarification or add additional context in comments.

1 Comment

Superb thank you Marek. Simple error on my part giving me grief!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.