用devise创建用户后(在视图中/不在设计页面中,使用Helpers)我重定向它们以在Papas控制器中创建模型条目(如果他们的角色是“Papa”)或者如果他们的角色是“Babysitter”则在保姆控制器中创建模型条目。 事情是我有一个奇怪的语法错误,因为两个控制器(爸爸和保姆)实际上是相等的。它给了我:
PapasController中的SyntaxError #new /Users/Seba/Desktop/PP/laguarderia/app/controllers/papas_controller.rb:75: 语法错误,意外的keyword_end,期望输入结束
但不是使用BabysitterController#new
这是控制器:
class PapasController < InheritedResources::Base
before_action :set_papa, only: [:show, :edit, :update, :destroy]
before_filter :authenticate_user!, except: [:new]
# GET /postulantes
# GET /postulantes.json
def index
@papas = Papa.all
end
# GET /postulantes/1
# GET /postulantes/1.json
def show
end
# GET /postulantes/new
def new
@papa = Papa.new
end
# GET /postulantes/1/edit
def edit
end
# POST /postulantes
# POST /postulantes.json
def create
@papa = Papa.new(papa_params)
@papa.user_id = current_user.id
respond_to do |format|
if @papa.save
format.html { redirect_to @papa, notice: '¡Tu postulación fue recibida con exito! Nos contactaremos contigo dentro de los próximos días.' }
format.json { render action: 'show', status: :created, location: @papas }
else
format.html { render action: 'new' }
format.json { render json: @papas.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /postulantes/1
# PATCH/PUT /postulantes/1.json
def update
respond_to do |format|
if @papa.update(papa_params)
format.html { redirect_to @papa, notice: 'Postulante was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @papa.errors, status: :unprocessable_entity }
end
end
end
# DELETE /postulantes/1
# DELETE /postulantes/1.json
def destroy
@papa.destroy
respond_to do |format|
format.html { redirect_to papas_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_papa
@papa = Papa.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def papa_params
params.require(:papa).permit(:nombre, :apellido1, :apellido2, :rut, :cumple, :estadocivil, :email, :cel, :fijo, :ciudad, :comuna, :calle, :numero, :depto, :profesion, :empresa, :cargo, :colegiohijos, :cantidadhijos, :edadhijos, :necesidad, :comentario, :user_id)
end
end
end
这是我的帮手:
module PagesHelper
def resource_name
:user
end
def resource
@resource = current_user || User.new
if @contact.save
if current_user.role == "Papa"
flash[:success] = "Thanks! I'll be in touch soon!"
redirect_to :action => 'papas/new'
elsif current_user.role == "Babysitter"
flash[:success] = "Thanks! I'll be in touch soon!"
redirect_to :action => 'babysitters/new'
else
flash[:success] = "hola"
redirect_to :action => 'home'
end
else
redirect_to :action => 'home'
end
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end
end
我意识到问题是什么。它不是控制器,它是由这个控制器控制的渲染形式中缺少的一端...你错过了愚蠢的事情:/
答案 0 :(得分:1)
错误强>
我不知道您对Rails的体验,但通常情况下,您收到的错误实际上意味着您没有关闭特定的代码块。
这可能是关闭括号的问题,包括某种变量声明,或者通常只是没有所需的end
定义
-
<强>控制器强>
首先,您使用的是inherited_resources
,但我不明白为什么您要设置new
,show
,edit
等方法,set_papa
等Inherited Reources
表示您不必设置 -
Class PapasController < InheritedResources::Base
before_filter :authenticate_user!, except: [:new]
# POST /postulantes
# POST /postulantes.json
def create
@papa = Papa.new(papa_params)
@papa.user_id = current_user.id
respond_to do |format|
if @papa.save
format.html { redirect_to @papa, notice: '¡Tu postulación fue recibida con exito! Nos contactaremos contigo dentro de los próximos días.' }
format.json { render action: 'show', status: :created, location: @papas }
else
format.html { render action: 'new' }
format.json { render json: @papas.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /postulantes/1
# PATCH/PUT /postulantes/1.json
def update
respond_to do |format|
if @papa.update(papa_params)
format.html { redirect_to @papa, notice: 'Postulante was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @papa.errors, status: :unprocessable_entity }
end
end
end
# DELETE /postulantes/1
# DELETE /postulantes/1.json
def destroy
@papa.destroy
respond_to do |format|
format.html { redirect_to papas_url }
format.json { head :no_content }
end
end
private
# Never trust parameters from the scary internet, only allow the white list through.
def papa_params
params.require(:papa).permit(:nombre, :apellido1, :apellido2, :rut, :cumple, :estadocivil, :email, :cel, :fijo, :ciudad, :comuna, :calle, :numero, :depto, :profesion, :empresa, :cargo, :colegiohijos, :cantidadhijos, :edadhijos, :necesidad, :comentario, :user_id)
end
end
-
<强>修正强>
我认为问题与你在课程结束时拥有的3 end
有关:
end
end
end
我认为您在尝试关闭private
区块时,它并不需要结束。在这里删除其中一个end
- (给你2
) - 它应该适合你