Colllection_check_boxes语法错误,意外',',期待')'

时间:2016-04-22 05:34:27

标签: ruby-on-rails

我正在使用helper collection_check_boxes:

<li class="form-fields__group">

    <label>Ownership type</label>
      <div class="field">
        <%= collection_check_boxes (:freelancer, :ownership_type_ids, OwnershipType.all, :id, :title) %>


      </div>
    </li>

在控制台错误中:

SyntaxError (/home/ubuntu/workspace/app/views/freelancers/edit.html.erb:192: syntax error, unexpected ',', expecting ')'
...ction_check_boxes (:freelancer, :ownership_type_ids, Ownersh...
...                               ^
/home/ubuntu/workspace/app/views/freelancers/edit.html.erb:192: syntax error, unexpected ',', expecting &. or :: or '[' or '.'
...pe_ids, OwnershipType.all, :id, :title) );@output_buffer.saf...
...                               ^
/home/ubuntu/workspace/app/views/freelancers/edit.html.erb:192: syntax error, unexpected ')', expecting keyword_end
...nershipType.all, :id, :title) );@output_buffer.safe_append='
...                               ^):

为什么会出现这个错误? collection_check_boxes有什么问题?

1 个答案:

答案 0 :(得分:1)

而不是:

<%= collection_check_boxes(:freelancer, :ownership_type_ids, OwnershipType.all, :id, :title) %>

删除空格:

public function login() {  
    if (!empty($this->request->data)){         
        $this->User->set($this->request->data);

        if ($this->User->validates(array('fieldList' => array('username','password')))){

            $user = $this->User->find('first', array(
                'conditions' => array(
                    'User.username' => $this->request->data['User']['username'],
                    'User.password' => md5($this->request->data['User']['password']),
                    'User.acc_type' => $this->request->data['User']['acc_type']                        
                )
            )); 

            if((!empty($user)) && ($user['User']['acc_type']==1)){
                 $this->redirect(array('controller' => 'users', 'action' => 'index'));
            }elseif((!empty($user)) && ($user['User']['acc_type']==2)){
                 $this->redirect(array('controller' => 'users', 'action' => 'add'));
            }
            else
            {
                $this->message('Invalid email / username or password');
            }
        }
    }
}