중첩 된 모델 양식을 사용하면 메서드 오류가 발생하지 않으며이를 파악할 수 없습니다. 어떤 도움이라도 대단히 감사하겠습니다. 동일한 양식으로 위치와 사용자를 생성하고 있습니다.중첩 된 폼에 메서드 오류가 없습니다.
오류
NoMethodError in Devise/registrations#new
/app/views/devise/registrations/new.html.erb where line #15 raised:
undefined method `build_location' for #<User:0x007fbafe371188>
Extracted source (around line #15):
12: <a class="add" href="http://www.google.com/placesforbusiness">Location not available? Click here to add it.</a>
13:
14: <!-- form for location info -->
15: <% resource.build_location %>
16: <%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {:class => 'form-vertical' }) do |f| %>
17: <%= f.error_notification %>
18: <%= f.fields_for :location do |location_form| %>
위치 모델
class Location < ActiveRecord::Base
has_and_belongs_to_many :users
accepts_nested_attributes_for :users, :allow_destroy => true
attr_accessible :lat, :long, :name, :street_address, :places_id, :users_attributes
validates_uniqueness_of :places_id, :message => "location already taken"
resourcify
end
위치 컨트롤러
def new
@location = Location.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @location }
end
end
# GET /locations/1/edit
def edit
@location = Location.find(params[:id])
end
# POST /locations
# POST /locations.json
def create
@location = @user.location.build(params[:location])
respond_to do |format|
if @location.save
format.html { redirect_to @location, notice: 'Location was successfully created.' }
format.json { render json: @location, status: :created, location: @location }
else
format.html { render action: "new" }
format.json { render json: @location.errors, status: :unprocessable_entity }
end
end
end
감사합니다. 그것이 그 것이다. user.locations.build로 변경해야했습니다. – jacobt