关于RoR的近声明

时间:2016-08-04 18:56:38

标签: ruby-on-rails mongoid

我正在尝试使用Mongoid在Rails上的用户之间建立联系。控制台显示一个SyntaxError,其中包含:

dic_size

这是控制器:

MyApp/app/controllers/contact_controller.rb:18: syntax error, unexpected end-of-input, expecting keyword_end

这是模型:

class ContactController < ApplicationController
  def addNew
    @newFriend = params[:username]
    puts "***value of @newFriend***"
    puts @newFriend
    puts "***end****"
    Contact.where(owner: current_user).where(friendlist: params[:username]) do |contact|
      puts "***value of @contactAlreadyExists***"
      puts contact
      puts "***end****"
      if contact == nil
        Contact.find_or_create_by(owner: current_user) do |contact|
          contact.push(friendlist: params[:username])
      end
    redirect_to "/"
  end
end

1 个答案:

答案 0 :(得分:1)

您在控制器中遗漏了end。检查下面的语法。

class ContactController < ApplicationController
  def addNew
    Contact.where(owner: current_user).where(friendlist: params[:username]) do |contact|
      ....

      if contact == nil
        Contact.find_or_create_by(owner: current_user) do |contact|

        <-- missing end  Contact.find_or_create_by ... do |contact|

       end <--- Okay with if block

     <-- missing end Contact.where ... do |contact|

    redirect_to "/"
  end  <--- Okay with fucntion addNew
end <--- Okay with ContactController