我有一个社交网络,为此我正在使用载波。我需要帮助进行设置,这样用户就不必创建图库名称来上传照片。这是carrierwave的默认设置,但由于这是一个社交网络,我不允许用户拥有不同的画廊(或专辑)。应该只有一个链接可以将照片上传到他们的个人资料。那么我应该如何攻击呢?顺便说一句,我是 Rails 的新手,所以任何和所有的帮助都将不胜感激!
照片控制器:
def new
@photo = Photo.new(:gallery_id => params[:gallery_id])
end
def create
@photo = Photo.new(params[:photo])
if @photo.save
flash[:notice] = "Successfully created photos."
redirect_to @photo.gallery
else
render :action => 'new'
end
end
def edit
@photo = Photo.find(params[:id])
end
def update
@photo = Photo.find(params[:id])
if @photo.update_attributes(paramas[:photo])
flash[:notice] = "Successfully updated photo."
redirect_to @photo.gallery
else
render :action => 'edit'
end
end
def destroy
@photo = Photo.find(params[:id])
@photo.destroy
flash[:notice] = "Successfully destroyed photo."
redirect_to @photo.gallery
end
end
画廊控制器:
def index
@galleries = Gallery.all
end
def show
@gallery = Gallery.find(params[:id])
end
def new
@gallery = Gallery.new
end
def create
@gallery = Gallery.new(params[:gallery])
if @gallery.save
flash[:notice] = "Successfully created gallery."
redirect_to @gallery
else
render :action => 'new'
end
end
def edit
@gallery = Gallery.find(params[:id])
end
def update
@gallery = Gallery.find(params[:id])
if @gallery.update_attributes(params[:gallery])
flash[:notice] = "Successfully updated gallery."
redirect_to gallery_url
else
render :action => 'edit'
end
end
def destroy
@gallery = Gallery.find(params[:id])
@gallery.destroy
flash[:notice] = "Successfully destroy gallery."
redirect_to galleries_url
end
end
路线:
Dating::Application.routes.draw do
get 'signup' => 'users#new'
get 'login' => 'sessions#new'
get 'logout' => 'sessions#destroy'
get 'edit' => 'users#edit'
get "/profile/:id" => "users#show"
get "profile/:id/settings" => 'users#edit'
match 'settings/:id' => 'users#settings'
resources :users
resources :sessions
resources :password_resets
resources :galleries
resources :photos
resources :searches
resources :users do
get 'settings', on: :member
end
root to: 'users#new'
root to: 'galleries#index'
resources :users do |user|
resources :messages do
collection do
post 'delete_multiple'
end
end
end