2016-08-03 77 views
0

我一直試圖使用'github_api'寶石來拉入信息。當我在終端中測試所有內容時,我可以將信息保存到我的用戶以及我創建的回購數據庫。然而,我把所有的信息放在我的控制器中,現在我不斷收到一個語法錯誤,意外的tLABEL,期待'='錯誤。以下是我的用戶控制器中的代碼和錯誤圖片。請幫忙!意外的tLABEL,期待'='錯誤

class UsersController < ApplicationController 

def index 
    @users = User.all 
end 

def create 
    @user = User.new 
     ( 
     id: Github.search.users(params[:name]).items[0].id, 
     username: Github.search.users(params[:name]).items[0].login, 
     html_url: Github.search.users(params[:name]).items[0].html_url, 
     avatar_url: Github.search.users(params[:name]).items[0].avatar_url 
     ) 
     end 

    if @user.save 
     Github.repos.list user: params[:name] do |repos| 
     Repo.create 
     (
      user_id: repos.owner.id, 
      name: repos.name, 
      address: repos.full_name 
     ) 
     end 
     redirect_to users_path 
    else 
     render users_path 
    end 
end 

def show 
    @user = User.find(id: params[:id]) 
end 

enter image description here

回答

1

當創建在同一行新用戶寫括號,也不需要end

@user = User.new( 
    id: Github.search.users(params[:name]).items[0].id, 
    username: Github.search.users(params[:name]).items[0].login, 
    html_url: Github.search.users(params[:name]).items[0].html_url, 
    avatar_url: Github.search.users(params[:name]).items[0].avatar_url 
) 

它的更好,如果你不使用圓括號噸知道你可以避開它們的地方:

if @user.save 
    Github.repos.list(user: params[:name]) do |repos| 
    Repo.create(
     user_id: repos.owner.id, 
     name: repos.name, 
     address: repos.full_name 
    ) 
    end 
    redirect_to users_path 
else 
    render users_path 
end 
+0

大聲笑,感謝編輯 – zishe

+1

你們真棒,它的工作! –

相關問題