안녕하세요, 저는 현재 첫 번째 프로젝트를 진행하고 있으며 로그인/세션을 수행하기 전에 기능을 먼저 구축하려고합니다. 나는 사진 앨범 웹 사이트를 만들려고합니다. 사용자가 많은 앨범 (많은 그림이 포함되어 있음)을 가지고 있으며 앨범 액세스는 친구 사이에서 공유됩니다. 그러나, 나는 albums#show
내 albums#create
레일 : 잘못 중첩되어 있습니까?
http://localhost:3000/users/18/albums/new
(여기에 아무 문제)
후 내가 리디렉션하고 있음에 주목하고 있습니다 :
http://localhost:3000/albums/20
(문제를!)
것은 없을해야 URL의 user_id도 ?? 또는 여러 사용자에게 속해 있기 때문에 URL에 user_id가 연결되어 있지 않습니까? 여기 내 경로는 다음과 같습니다 여기
Pholder::Application.routes.draw do
resources :users do
resources :albums
end
resources :albums do
resources :pictures
end
root :to => "users#index"
는 경우에 내 모델입니다 :
사용자 모델
class User < ActiveRecord::Base
has_secure_password
attr_accessible :email, :name, :password, :password_confirmation
validates_presence_of :password, :on => :create
validates_format_of :name, :with => /[A-Za-z]+/, :on => :create
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :create
validates_length_of :password, :minimum => 5, :on => :create
has_many :user_albums
has_many :albums, :through => :user_albums
accepts_nested_attributes_for :albums
end
앨범 모델
class Album < ActiveRecord::Base
attr_accessible :avatar, :name, :description
has_many :user_albums
has_many :users, :through => :user_albums
has_many :photos
end
사진 앨범
class Photo < ActiveRecord::Base
belongs_to :album
end
앨범 컨트롤러
class AlbumsController < ApplicationController
def index
@albums = Albums.all
respond_to do |format|
format.html
format.json { render json: @albums }
end
end
def show
@albums = Album.all
@album = Album.find(params[:id])
@photo = Photo.new
end
def update
end
def edit
end
def create
# @user = User.find(params[:albums][:user_id])
# @users = User.all
@album = Album.new(params[:album])
# @album.user_id = @user.id
respond_to do |format|
if @album.save
format.html { redirect_to @album, notice: 'Album was successfully created.' }
format.json { render json: @album, status: :created, location: @album}
else
format.html { render action: "new" }
format.json { render json: @album.errors, status: :unprocessable_entity }
end
end
end
def new
@user = User.find(params[:user_id])
@album = Album.new
end
def destroy
end
end
는 다른 파일이 필요하면 알려주세요.
글쎄, 그것은 컨트롤러입니다. – MurifoX
내가 볼 수 있도록 앨범 컨트롤러를 업로드했습니다. @ 앨범 인스턴스 변수가 잘못 되었습니까? – Edmund