form_for がフォームとして渡されません。通常は問題を解決できますが、これは から 2 つの引数が渡される理由がわかりません@image
。これが私のコードです
エラー
wrong number of arguments (2 for 1)
意見
<% form_for @image, :action => "edit" do |f| %>
<%= f.text_field :title %>
<%= f.submit "Update" %>
<% end %>
コントローラ
class Admin::ImagesController < ApplicationController
respond_to :html, :json
def index
@album = Album.find(params[:album_id])
@images = Image.all
end
def new
@album = Album.find(params[:album_id])
@image = @album.images.new(params[:image_id])
end
def create
@album = Album.find(params[:album_id])
@image = @album.images.new(params[:image])
if @image.save
flash[:notice] = "Successfully added image!"
redirect_to [:admin, @album, :images]
else
render :action => 'new'
end
end
def show
@album = Album.find(params[:album_id])
@image = @album.images(params[:id])
end
def edit
@album = Album.find(params[:album_id])
@image = @album.images(params[:id])
end
def update
@album = Album.find(params[:album_id])
@image = @album.images(params[:id])
if @image.update_attributes(params[:image])
flash[:notice] = "Successfully updated Image"
redirect_to @image
else
render :action => "edit"
end
end
def destroy
@album = Album.find(params[:album_id])
@image = Image.find(params[:id])
@image.destroy
redirect_to admin_album_images_path(@album)
end
end
ルート
Admin::Application.routes.draw do
get "albums/index"
get "dashboard/index"
namespace :admin do
root :to => "dashboard#index"
resources :dashboard
resources :albums do
resources :images
end
get "admin/album"
end
get "logout" => "sessions#destroy", :as => "logout"
get "login" => "sessions#new", :as => "login"
get "signup" => "users#new", :as => "signup"
# resources :users
resources :basic
root :to => "basic#index"
モデル
class Image < ActiveRecord::Base
attr_accessible :title, :description, :image_name, :image_id, :album_id
belongs_to :album
accepts_nested_attributes_for :album
end