1

我得到了專輯控制器這種不確定的方法與模型的任何解決方案...未定義的方法`MODEL_NAME「

未定義的方法`MODEL_NAME?」 ActiveRecord的::關係:類

提取的源(左右線#6):

3:>>

4:新專輯

5:

6:= form_for @albums do | f |

7:= f.error_messages

8:%P

9:= f.label:命名


=link_to 'albums', albums_path 
     >> 
     new album 
    = form_for @album do |f| 
     = f.error_messages 
    %p 
    = f.label :name 
    = f.text_field :name 

    %p 
    = f.label :description 
    = f.text_field :description, :rows => 3 
    %p 
    = f.submit 

%p= link_to "Back to List", albums_path 

class AlbumsController < ApplicationController 
    before_filter :authenticate_user! 

    respond_to :html 
    respond_to :json 

    def index 
    @albums = current_user.albums.paginate :page => params[:page], :per_page => 9, :order => 'created_at DESC' 
    respond_with @albums, :aspect => @aspect 
    end 

    def create 
    aspect = params[:album][:to] 

    @album = current_user.post(:album, params[:album]) 
    if @album.persisted? 
     redirect_to :action => :show, :id => @album.id, :aspect => aspect 
    else 
     redirect_to albums_path(:aspect => aspect) 
    end 
    end 

    def new 
    @album = Album.new 
    end 

    def destroy 
    @album = current_user.find_visible_post_by_id params[:id] 
    @album.destroy 
    respond_with :location => albums_url 
    end 

    def show 
    @person = current_user.visible_people.find_by_person_id(params[:person_id]) if params[:person_id] 
    @person ||= current_user.person 

    @album = :uploads if params[:id] == "uploads" 
    @album ||= current_user.find_visible_post_by_id(params[:id]) 

    unless @album 
     render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404 
    else 

     if @album == :uploads 
     @album_id = nil 
     @album_name = "Uploads" 
     @album_photos = current_user.visible_posts(:_type => "Photo", :album_id => nil, :person_id => @person.id) 

     else 
     @album_id = @album.id 
     @album_name = @album.name 
     @album_photos = @album.photos 
     end 

     respond_with @album 
    end 
    end 

    def edit 
    @album = current_user.find_visible_post_by_id params[:id] 
    redirect_to @album unless current_user.owns? @album 
    end 

    def update 
    @album = current_user.find_visible_post_by_id params[:id] 

    if current_user.update_post(@album, params[:album]) 
     respond_with @album 
    else 
     render :action => :edit 
    end 
    end 

end 

class Album < ActiveRecord::Base 
    include ROXML 
    xml_attr :name 
    xml_attr :description 

    belongs_to :user 
    belongs_to :person 
    validates :person, :presence => true 

    has_many :photos, :class_name => 'Photo', :foreign_key => :album_id 

    validates_presence_of :name 
    validates :person, :presence => true 



    before_destroy :destroy_photos 

     attr_accessible :name 
end 

回答

2
=form_for @albums do |f| 

應該

=form_for @album do |f| 

@album VS @albums,只是根據你的錯誤消息猜測這裏,在你的代碼示例,它看起來是正確的,不知道他們會如何不同?錯誤來自新的操作?

0

從這個錯誤發生的時候,你不清楚你的問題是什麼時候發生的 - 你已經把代碼發佈到了六種方法,但是你沒有說出哪一個會導致這個錯誤。來自錯誤回溯的源也與您在其下面粘貼的源不匹配。

(而不是你似乎傳遞範圍form_for,這是沒有意義的)什麼錯誤是說大致是你試圖調用的東西像form_for不足夠看起來像一個ActiveModel對象。做form_for @albums肯定會觸發這一點。

相關問題