0
問題:當我訪問create.save
時,出現錯誤ActionController::UnknownFormat in GuestsController#create
,通過記錄保存。任何想法如何擺脫它?用CRUD設計模型
我:
rails g devise guest
;rails g controller guests
適用於CRUD界面。
guests_controller.rb:
class GuestsController < ApplicationController
before_action :set_guest, only: [:show, :edit, :update, :destroy]
def new
@guest = Guest.new
end
def edit
@guest = Guest.find(params[:id])
end
def create
respond_to do |format|
@guest = Guest.new(guest_params)
if @guest.save
redirect_to guests_path, notice: 'Client was successfully created.'
else
render :new
end
end
end
def update
#update without changing password
if params[:guest][:password].blank?
params[:guest].delete(:password)
params[:guest].delete(:password_confirmation)
end
#usual actions
@guest = Guest.find(params[:id])
if @guest.update_attributes(guest_params)
sign_in(@guest, :bypass => true) if @guest == current_guest
redirect_to guests_path, notice: 'Client was successfully updated.'
else
render :edit
end
end
private
def set_guest
@guest = Guest.find(params[:id])
end
def guest_params
params.require(:guest).permit(:email, :password, :password_confirmation)
end
end
可能有一些在註冊/控制器重定向...
我試過路線devise_for :guests, controllers: { registrations: 'guest_registrations' }
+ guest_registrations_controller.rb
:
class GuestRegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(guest)
guests_path # Or :prefix_to_your_route
end
end
,但什麼也沒做
它的工作:)我想我有相同的添加到'update'行動。謝謝,Rahul –
是的,如果你要處理多個響應格式。 –