Home php c# sql c c++ javascript python java go android git linux asp.net django .net node.js ios xcode cocoa iphone mysql tomcat mongodb bash objective-c scala visual-studio apache elasticsearch jar eclipse jquery ruby-on-rails ruby rubygems android-studio spring lua sqlite emacs ubuntu perl docker swift amazon-web-services svn html ajax xml java-ee maven intellij-idea rvm macos unix css ipad postgresql css3 json windows-server vue.js typescript oracle hibernate internet-explorer github tensorflow laravel symfony redis html5 google-app-engine nginx firefox sqlalchemy lucene erlang flask vim solr webview facebook zend-framework virtualenv nosql ide twitter safari flutter bundle phonegap centos Register | Login | Edit Tags | New Questions | 繁体 | 简体


7 questions online user: 39

0
votes
answers
6 views
+10

在軌道上安裝寶石,紅寶石。使用JSON錯誤

0

我目前正試圖創建具有軌道新的應用程序,希望在我的應用程序目錄下安裝寶石,得到了以下信息:在軌道上安裝寶石,紅寶石。使用JSON錯誤

[email protected]:/dev/movies-forum# bundle install --path vendor/bundle 
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and 
installing your bundle as root will break this application for all non-root 
users on this machine. 
Fetching gem metadata from https://rubygems.org/........... 
Fetching version metadata from https://rubygems.org/... 
Fetching dependency metadata from https://rubygems.org/.. 
Resolving dependencies.... 
Installing rake 12.3.0 
Installing concurrent-ruby 1.0.5 
Installing json 1.8.6 with native extensions 

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. 

    current directory: /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/json-1.8.6/ext/json/ext/generator 
/usr/bin/ruby2.3 -r ./siteconf20171125-3993-154eb9h.rb extconf.rb 
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h 

extconf failed, exit code 1 

Gem files will remain installed in /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/json-1.8.6 for inspection. 
Results logged to /dev/movies-forum/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/json-1.8.6/gem_make.out 
Installing minitest 5.10.3 
Installing thread_safe 0.3.6 
Installing builder 3.2.3 
Installing erubis 2.7.0 
Installing mini_portile2 2.3.0 
Installing crass 1.0.3 
Installing rack 1.6.8 
Installing mini_mime 1.0.0 
Installing arel 6.0.4 
Installing debug_inspector 0.0.3 with native extensions 

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. 

    current directory: /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/debug_inspector-0.0.3/ext/debug_inspector 
/usr/bin/ruby2.3 -r ./siteconf20171125-3993-1n3hl3h.rb extconf.rb 
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h 

extconf failed, exit code 1 

Gem files will remain installed in /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/debug_inspector-0.0.3 for inspection. 
Results logged to /dev/movies-forum/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/debug_inspector-0.0.3/gem_make.out 
Using bundler 1.11.2 
Installing byebug 9.1.0 with native extensions 

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. 

    current directory: /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/byebug-9.1.0/ext/byebug 
/usr/bin/ruby2.3 -r ./siteconf20171125-3993-g49k1z.rb extconf.rb 
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h 

extconf failed, exit code 1 

Gem files will remain installed in /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/byebug-9.1.0 for inspection. 
Results logged to /dev/movies-forum/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/byebug-9.1.0/gem_make.out 
Installing coffee-script-source 1.12.2 
Installing execjs 2.7.0 
Installing thor 0.20.0 
Installing ffi 1.9.18 with native extensions 

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. 

    current directory: /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/ffi-1.9.18/ext/ffi_c 
/usr/bin/ruby2.3 -r ./siteconf20171125-3993-yzalv6.rb extconf.rb 
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h 

extconf failed, exit code 1 

Gem files will remain installed in /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/ffi-1.9.18 for inspection. 
Results logged to /dev/movies-forum/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/ffi-1.9.18/gem_make.out 
Installing multi_json 1.12.2 
Installing rb-fsevent 0.10.2 
Installing rdoc 4.3.0 
Installing tilt 2.0.8 
Installing sqlite3 1.3.13 with native extensions 

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. 

    current directory: /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/sqlite3-1.3.13/ext/sqlite3 
/usr/bin/ruby2.3 -r ./siteconf20171125-3993-1y1q30j.rb extconf.rb 
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h 

extconf failed, exit code 1 

Gem files will remain installed in /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/sqlite3-1.3.13 for inspection. 
Results logged to /dev/movies-forum/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/sqlite3-1.3.13/gem_make.out 
Installing turbolinks-source 5.0.3 
Installing i18n 0.9.1 
An error occurred while installing json (1.8.6), and Bundler cannot continue. 
Make sure that `gem install json -v '1.8.6'` succeeds before bundling. 
[email protected]:/dev/movies-forum# gem install json -v '1.8.6' 
Fetching: json-1.8.6.gem (100%) 
Building native extensions. This could take a while... 
ERROR: Error installing json: 
    ERROR: Failed to build gem native extension. 

    current directory: /var/lib/gems/2.3.0/gems/json-1.8.6/ext/json/ext/generator 
/usr/bin/ruby2.3 -r ./siteconf20171125-4056-c2r6jm.rb extconf.rb 
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h 

extconf failed, exit code 1 

Gem files will remain installed in /var/lib/gems/2.3.0/gems/json-1.8.6 for inspection. 
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/json-1.8.6/gem_make.out 
[email protected]:/dev/movies-forum# which bundler 
/usr/bin/bundler 
[email protected]:/dev/movies-forum# gem install bundler && rbenv rehash 
Fetching: bundler-1.16.0.gem (100%) 
Successfully installed bundler-1.16.0 
Parsing documentation for bundler-1.16.0 
Installing ri documentation for bundler-1.16.0 
Done installing documentation for bundler after 4 seconds 
1 gem installed 
Program rbenv nie jest obecnie zainstalowany. Mo?esz go zainstalowa? wpisuj?c: 
apt install rbenv 
[email protected]:/dev/movies-forum# bundle install --path vendor/bundle 
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and 
installing your bundle as root will break this application for all non-root 
users on this machine. 
Fetching gem metadata from https://rubygems.org/........... 
Fetching version metadata from https://rubygems.org/... 
Fetching dependency metadata from https://rubygems.org/.. 
Resolving dependencies.... 
Using rake 12.3.0 
Using concurrent-ruby 1.0.5 
Installing json 1.8.6 with native extensions 

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. 

    current directory: /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/json-1.8.6/ext/json/ext/generator 
/usr/bin/ruby2.3 -r ./siteconf20171125-4146-njwwhh.rb extconf.rb 
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h 

extconf failed, exit code 1 

Gem files will remain installed in /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/json-1.8.6 for inspection. 
Results logged to /dev/movies-forum/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/json-1.8.6/gem_make.out 
Using minitest 5.10.3 
Using thread_safe 0.3.6 
Using builder 3.2.3 
Using erubis 2.7.0 
Using mini_portile2 2.3.0 
Using crass 1.0.3 
Using rack 1.6.8 
Using mini_mime 1.0.0 
Using arel 6.0.4 
Installing debug_inspector 0.0.3 with native extensions 

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. 

    current directory: /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/debug_inspector-0.0.3/ext/debug_inspector 
/usr/bin/ruby2.3 -r ./siteconf20171125-4146-r39wqa.rb extconf.rb 
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h 

extconf failed, exit code 1 

Gem files will remain installed in /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/debug_inspector-0.0.3 for inspection. 
Results logged to /dev/movies-forum/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/debug_inspector-0.0.3/gem_make.out 
Using bundler 1.11.2 
Installing byebug 9.1.0 with native extensions 

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. 

    current directory: /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/byebug-9.1.0/ext/byebug 
/usr/bin/ruby2.3 -r ./siteconf20171125-4146-16t55au.rb extconf.rb 
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h 

extconf failed, exit code 1 

Gem files will remain installed in /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/byebug-9.1.0 for inspection. 
Results logged to /dev/movies-forum/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/byebug-9.1.0/gem_make.out 
Using coffee-script-source 1.12.2 
Using execjs 2.7.0 
Using thor 0.20.0 
Installing ffi 1.9.18 with native extensions 

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. 

    current directory: /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/ffi-1.9.18/ext/ffi_c 
/usr/bin/ruby2.3 -r ./siteconf20171125-4146-ngcier.rb extconf.rb 
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h 

extconf failed, exit code 1 

Gem files will remain installed in /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/ffi-1.9.18 for inspection. 
Results logged to /dev/movies-forum/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/ffi-1.9.18/gem_make.out 
Using multi_json 1.12.2 
Using rb-fsevent 0.10.2 
Using rdoc 4.3.0 
Using tilt 2.0.8 
Installing sqlite3 1.3.13 with native extensions 

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. 

    current directory: /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/sqlite3-1.3.13/ext/sqlite3 
/usr/bin/ruby2.3 -r ./siteconf20171125-4146-9yhg8k.rb extconf.rb 
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h 

extconf failed, exit code 1 

Gem files will remain installed in /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/sqlite3-1.3.13 for inspection. 
Results logged to /dev/movies-forum/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/sqlite3-1.3.13/gem_make.out 
Using turbolinks-source 5.0.3 
Using i18n 0.9.1 
An error occurred while installing json (1.8.6), and Bundler cannot continue. 
Make sure that `gem install json -v '1.8.6'` succeeds before bundling. 
[email protected]:/dev/movies-forum# 
[email protected]:/dev/movies-forum# gem bundler install 
ERROR: While executing gem ... (Gem::CommandLineError) 
    Unknown command bundler 
[email protected]:/dev/movies-forum# sudo gem install bundler 
Successfully installed bundler-1.16.0 
Parsing documentation for bundler-1.16.0 
Done installing documentation for bundler after 3 seconds 
1 gem installed 
[email protected]:/dev/movies-forum# bundle install --path vendor/bundle 
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and 
installing your bundle as root will break this application for all non-root 
users on this machine. 
Fetching gem metadata from https://rubygems.org/........... 
Fetching version metadata from https://rubygems.org/... 
Fetching dependency metadata from https://rubygems.org/.. 
Resolving dependencies.... 
Using rake 12.3.0 
Using concurrent-ruby 1.0.5 
Installing json 1.8.6 with native extensions 

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. 

    current directory: /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/json-1.8.6/ext/json/ext/generator 
/usr/bin/ruby2.3 -r ./siteconf20171125-4191-1krkby3.rb extconf.rb 
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h 

extconf failed, exit code 1 

Gem files will remain installed in /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/json-1.8.6 for inspection. 
Results logged to /dev/movies-forum/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/json-1.8.6/gem_make.out 
Using minitest 5.10.3 
Using thread_safe 0.3.6 
Using builder 3.2.3 
Using erubis 2.7.0 
Using mini_portile2 2.3.0 
Using crass 1.0.3 
Using rack 1.6.8 
Using mini_mime 1.0.0 
Using arel 6.0.4 
Installing debug_inspector 0.0.3 with native extensions 

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. 

    current directory: /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/debug_inspector-0.0.3/ext/debug_inspector 
/usr/bin/ruby2.3 -r ./siteconf20171125-4191-3mbadh.rb extconf.rb 
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h 

extconf failed, exit code 1 

Gem files will remain installed in /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/debug_inspector-0.0.3 for inspection. 
Results logged to /dev/movies-forum/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/debug_inspector-0.0.3/gem_make.out 
Using bundler 1.11.2 
Installing byebug 9.1.0 with native extensions 

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. 

    current directory: /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/byebug-9.1.0/ext/byebug 
/usr/bin/ruby2.3 -r ./siteconf20171125-4191-1ihoksu.rb extconf.rb 
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h 

extconf failed, exit code 1 

Gem files will remain installed in /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/byebug-9.1.0 for inspection. 
Results logged to /dev/movies-forum/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/byebug-9.1.0/gem_make.out 
Using coffee-script-source 1.12.2 
Using execjs 2.7.0 
Using thor 0.20.0 
Installing ffi 1.9.18 with native extensions 

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. 

    current directory: /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/ffi-1.9.18/ext/ffi_c 
/usr/bin/ruby2.3 -r ./siteconf20171125-4191-ns9wm1.rb extconf.rb 
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h 

extconf failed, exit code 1 

Gem files will remain installed in /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/ffi-1.9.18 for inspection. 
Results logged to /dev/movies-forum/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/ffi-1.9.18/gem_make.out 
Using multi_json 1.12.2 
Using rb-fsevent 0.10.2 
Using rdoc 4.3.0 
Using tilt 2.0.8 
Installing sqlite3 1.3.13 with native extensions 

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. 

    current directory: /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/sqlite3-1.3.13/ext/sqlite3 
/usr/bin/ruby2.3 -r ./siteconf20171125-4191-1hupaig.rb extconf.rb 
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h 

extconf failed, exit code 1 

Gem files will remain installed in /dev/movies-forum/vendor/bundle/ruby/2.3.0/gems/sqlite3-1.3.13 for inspection. 
Results logged to /dev/movies-forum/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/sqlite3-1.3.13/gem_make.out 
Using turbolinks-source 5.0.3 
Using i18n 0.9.1 
An error occurred while installing json (1.8.6), and Bundler cannot continue. 
Make sure that `gem install json -v '1.8.6'` succeeds before bundling. 

顯然,我所做的就是:

[email protected]:/dev/movies-forum# gem install json -v '1.8.6' 
Building native extensions. This could take a while... 
ERROR: Error installing json: 
    ERROR: Failed to build gem native extension. 

    current directory: /var/lib/gems/2.3.0/gems/json-1.8.6/ext/json/ext/generator 
/usr/bin/ruby2.3 -r ./siteconf20171125-4328-ttizdh.rb extconf.rb 
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h 

extconf failed, exit code 1 

Gem files will remain installed in /var/lib/gems/2.3.0/gems/json-1.8.6 for inspection. 
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/json-1.8.6/gem_make.out 

我應該如何處理所有這些錯誤?我在.../gems中有一個json-1.8.6目錄。我在那裏看到24個其他寶石,但不應該在70左右?我並不是真正的鐵桿專家,這是我的第一次嘗試。

沙发
0
0

這裏就是我沒有和它幫助:

apt-get install ruby-dev 

當我試圖主機一臺服務器有一個與「uglifier」一個問題,但這個幫助:

sudo apt-get install nodejs 
0
votes
answers
5 views
+10

如何使用ruby線程在類中運行一個方法?

-2

我有一個類和屬性有如何使用ruby線程在類中運行一個方法?

class Person 
    attr_accessor :name 
    def say_hello 
    puts "person name #{self.name} " 
    end 
end 

現在我想執行say_hello但這個線程

queue_thread= [] 
1..100.times do |number| 
    person= Person.new 
    person.name= number.to_s 
    thread_to_run=Thread.new {person.say_hello} 
    queue_thread << thread_to_run 
end 
queue_thread.map {|thread_current| thread_current.join} 

你有一些想法如何做到這一點的方法是什麼?我看和prprmm比線程是不識別對象的實例的變量。

正確的答案應該是這個控制檯

"person name 1" 
"person name 2" 
"person name ..." 
"person name etc" 
+0

你會得到什麼?作爲一個說明,多個線程同時寫入控制檯是一個很好的混合方式。一個線程應該處理輸出。 – tadman

+0

感謝您的回答,我再次編輯,我需要通過控制檯獲取人名1,人名2,人名3。你可以幫我嗎 ? –

+0

如果你需要這個順序,線程會搞砸了。你爲什麼穿線?您需要以某種方式收集輸出並在顯示之前進行排序。 – tadman

沙发
0
0

這段代碼的問題是它火災關閉多個線程調用join之前 - 就在這個時候,一些線程可稱爲由於線程的異步性質,所以順序不正確。

只要線程被調用,一個選項就是簡單地join。這實際上將暫停迭代,直到線程完成,所以你知道他們會留在順序:

100.times do |number| 
    person= Person.new 
    person.name= number.to_s 
    Thread.new {person.say_hello}.join 
end 

注有真的在這裏使用一個線程是沒有意義的,但它至少表明你可以join作品。

另一個選項(也不必要地使用線程)是通過將線程調用存儲爲lambda來延遲線程調用。這是基本相同的事情,但可以讓你它分成兩個迭代:

queue_threads= [] 
1..100.times do |number| 
    person= Person.new 
    person.name= number.to_s 
    thread_lambda = -> { Thread.new {person.say_hello} } 
    queue_threads.push(thread_lambda) 
end 
queue_threads.map {|thread_lambda| thread_lambda.call.join} 

還要注意的是1..100.times沒有做什麼,你認爲它是。這與說100.times是一回事,例如,如果你說99..100.times,99被忽略,它將是100次迭代,而不是1次。如果你想迭代一個範圍,你可以使用像99..100.each do |i|這樣的東西。

0
votes
answers
5 views
+10

無法創建色器件

0

使用設備的任務,不能創建任務 我的模型 用戶無法創建色器件

class User < ApplicationRecord 
    # Include default devise modules. Others available are: 
    # :confirmable, :lockable, :timeoutable and :omniauthable 
    devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, :validatable 

    has_many :tasks 
end 

任務

class Task < ApplicationRecord 
    belongs_to :user 
end 

任務控制器

def create 
    @task = Task.new(task_params) 

    respond_to do |format| 
     if @task.save 
     format.html { redirect_to @task, notice: 'Task was successfully created.' } 
     format.json { render :show, status: :created, location: @task } 
     else 
     format.html { render :new } 
     format.json { render json: @task.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

,並試圖在創建任務有錯誤

1錯誤禁止被保存在這個任務:

User must exist 

我的反應

開始POST 「/任務」 爲127.0.0.1,在2017年12月27日14時20分59秒0200 處理由TasksController#創建以HTML 參數:{ 「UTF8」=> 「?」, 「authenticity_token」=> 「b7EkQsJygYBW1xLIm1uFD8jluXy2LYeoYjAOjKcwWOMHLwtalXmkTrNJu0yhexucwY94COegDcuVrOWLRkf8dg ==」, 「任務」=> { 「標題」=> 「」,「描述「=>」「,」優先「=>」「,」due(1i)「=>」2017「,」due(2i)「=>」12「,」due(3i)「=>」27「 ,「完成」=>「0」},「提交」=>「創建任務」}

User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 2], ["LIMIT", 1]] 
    (0.0ms) begin transaction 
    (0.1ms) rollback transaction 

怎麼了?

沙发
0
0

更改belongs_to :userbelongs_to :user, optional: true。 Rails 5引入了關聯中的默認驗證。請參閱this link更好地理解

+0

它的工作原理,但不是正確的。當我添加到new_task_view

<%= form.label :user_id %> <%= form.text_field :user_id, id: :task_done %>
n它的工作原理我whant,但我需要勉強把用戶的ID。我希望自動執行此操作 – asda111sd

板凳
0
0

的方法創建控制器需要添加@task.user_id = current_user.id

+0

這不能提供問題的答案。要批評或要求作者澄清,請在其帖子下方留言。 - [來自評論](/ review/low-quality-posts/18362806) – Mamun

+0

這是一個答案。它可以使用更多的解釋,但它是一個答案。 –

地板
0
0

要知道,工作是不是按照https://reservedwords.herokuapp.com/words/task?q[word_or_notes_cont]=task

在Rails的模型好名字沒有保留字完整列表因爲語言和框架的性質。但是,當你使用衝突的關鍵字時,有時你會面對奇怪的行爲。

4楼
0
0

你丟失了user_id創建task

嘗試以下

在你的代碼

def create 
    @task = Task.new(task_params) 

    respond_to do |format| 
    if @task.save 
     format.html { redirect_to @task, notice: 'Task was successfully created.' } 
     format.json { render :show, status: :created, location: @task } 
    else 
     format.html { render :new } 
     format.json { render json: @task.errors, status: :unprocessable_entity } 
    end 
    end 
end 

從您的代碼修改,您可以使用

def create 
    @task = Task.new(task_params) 
    @task.user = current_user 

    respond_to do |format| 
    if @task.save 
     format.html { redirect_to @task, notice: 'Task was successfully created.' } 
     format.json { render :show, status: :created, location: @task } 
    else 
     format.html { render :new } 
     format.json { render json: @task.errors, status: :unprocessable_entity } 
    end 
    end 
end 

希望幫助

0
votes
answers
5 views
+10

如何從文件中讀取文本到ruby中的數組

0

有沒有辦法將net-ssh gem中的HOST,USER,PASS varibales視爲一個數組,並且有多個值?如何從文件中讀取文本到ruby中的數組

我目前有一個帶有HOST,USER和PASS值的外部文本文件,但是我需要將這些內容傳遞給net-ssh gem中的上述變量。

任何幫助和編輯來澄清問題,我們感謝! :)

沙发
0
1

你應該可以使用splat操作符來做到這一點。請仔細閱讀此內容,但Google很快會返回this介紹。使用此方法,您可以將一組參數傳遞給您描述的方法。喜歡的東西:

some_values = ['host_name', 'user_name', 'password'] 
some_method(*some_values) 

如果你可以更新您的問題,包括一些例如輸入,你試過到目前爲止,與期望的結果,那會是非常方便的進入更多的細節。

我不確定在讀取文件/值之前是否出現問題。如果是這樣,給我看文件格式,我會想一想 - 你可能需要使用像File.read('your_file.txt')這樣的東西。

否則,請考慮將值存儲在YAML文件中,這是用於在鐵路應用程序之外存儲敏感變量的常用模式。藉此,您可以加載文件並以散列形式訪問數據,並作爲參數傳遞。

這有幫助嗎?希望如此 - 如果沒有,請在問題中增加一些細節,我會更新以反映這一點。

+0

感謝您的迴應!我會試試這個。我不熟悉腳本(ruby),所以我的語法可能是另一個問題。讓我嘗試發佈相關代碼 – CreeFC

0
votes
answers
4 views
+10

我正在嘗試在紅寶石中安裝OpenGraph寶石

0

我搜索了整個網絡尋找解決此錯誤的方法。但它不會讓步。根據我的知識,我安裝了所有的庫和依賴項,甚至卸載了ruby和nokogiri並重新安裝。但是這個錯誤仍然存??在。 我正在嘗試在紅寶石中安裝OpenGraph寶石

Gem files will remain installed in /home/$User/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/nokogiri-1.4.7 for inspection. 
 
Results logged to /home/$User/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/extensions/x86_64-linux/2.4.0-static/nokogiri-1.4.7/gem_make.out

這是從這個位置gem_make.out日誌文件 - > /.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/extensions/x86_64-linux/ 2.4.0靜電/引入nokogiri-1.4.7/gem_make.out

ERROR: Error installing opengraph: 
 
	 ERROR: Failed to build gem native extension. 
 

 
    current directory: /home/$User/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/nokogiri-1.4.7/ext/nokogiri 
 
/home/$User/.rbenv/versions/2.4.2/bin/ruby -r ./siteconf20171125-15877-nibcps.rb extconf.rb --with-nokogiri-dir=/home/$User/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/ 
 
*** extconf.rb failed *** 
 
Could not create Makefile due to some reason, probably lack of necessary 
 
libraries and/or headers. Check the mkmf.log file for more details. You may 
 
need configuration options. 
 

 
Provided configuration options: 
 
	 --with-opt-dir 
 
	 --without-opt-dir 
 
	 --with-opt-include 
 
	 --without-opt-include=${opt-dir}/include 
 
	 --with-opt-lib 
 
	 --without-opt-lib=${opt-dir}/lib 
 
	 --with-make-prog 
 
	 --without-make-prog 
 
	 --srcdir=. 
 
	 --curdir 
 
	 --ruby=/home/$User/.rbenv/versions/2.4.2/bin/$(RUBY_BASE_NAME) 
 
extconf.rb:10:in `<main>': uninitialized constant Config (NameError) 
 
Did you mean? RbConfig 
 
       CONFIG 
 

 
extconf failed, exit code 1
我會很感激你,如果你能告訴我什麼是錯的。這是OpenGraph中的錯誤嗎?

P.S:我沒有使用opengraph_parser,因爲它有一個回退方法。我需要opengraph寶石,因爲我需要捕捉異常。

沙发
0
0

它不是opengraph,而是nokogiri。

Nokogiri是opengraph的依賴項。 https://rubygems.org/gems/opengraph/versions/0.0.4

因此,它必須在您的機器上沒有支持nokogiri(libxml2)所需的依賴關係。

安裝你的機器上,這些依賴關係(上於Debian/Ubuntu假設你):

sudo apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev 

的Fedora /紅帽/ CentOS的:

sudo yum install -y gcc ruby-devel zlib-devel 
sudo yum install -y rubygem-nokogiri (alternative) 

然後嘗試通過gem install nokogiri安裝引入nokogiri

對於其他變體或操作系統: http://www.nokogiri.org/tutorials/installing_nokogiri.html

於Fedora 26: 直至另行通知,安裝引入nokogiri版本< 1.8

+0

Hi..thanks的答覆。但我使用的是Fedora 26.你能告訴我Fedora或任何Redhat的類似依賴嗎? – Meimo

+0

@Meimo ruby??-devel zlib-devel。更新了我的答案。 – jemonsanto

+0

感謝您再次回覆,但我試圖安裝這些依賴關係時...終端說「已安裝,無事可做」。看到我告訴你,根據我的知識安裝一切。但它只是不會安裝。我認爲這是一個錯誤。 – Meimo

0
votes
answers
4 views
+10

Rails:更改will_paginate gem的next_page類

0

是否可以更改將paginate gem的類名'next_page'?例如很容易改變.paginate類,但我不知道,如果一旦你被允許改變封閉類的名稱,改變嵌套類的名稱是不可能性與「next_page」Rails:更改will_paginate gem的next_page類

:class - CSS class name for the generated DIV (default: "pagination") 
:previous_label - default: "« Previous" 
:next_label - default: "Next »" 
:page_links - when false, only previous/next links are rendered (default: true) 
:inner_window - how many links are shown around the current page (default: 4) 
:outer_window - how many links are around the first and the last page (default: 1) 
:link_separator - string separator for page HTML elements (default: single space) 
:param_name - parameter name for page number in URLs (default: :page) 
:params - additional parameters when generating pagination links (eg.    :controller => "foo", :action => nil) 
:renderer - class name, class or instance of a link renderer (default in Rails: WillPaginate::ActionView::LinkRenderer) 
:container - toggles rendering of the DIV container for pagination links, set to false only when you are rendering your own pagination markup (default: true) 
+0

爲什麼你需要改變類名? –

沙发
0
0

是多餘的,因此沒有提供。

使用CSS選擇器.pagination > .next_page來避免任何可能的名稱衝突。

0
votes
answers
3 views
+10

高Sierra 10.13.1和Rails的問題?

0

我已經嘗試在高塞拉利昂安裝Rails,但不斷收到「無法構建gem本機擴展」錯誤。高Sierra 10.13.1和Rails的問題?

checking for sys/epoll.h... no

^這是我需要做什麼來看着。我不確定這是否是新操作系統的問題...可能是nio4r-2.1.0的問題?

Building native extensions. This could take a while... 
 
ERROR: Error installing rails: 
 
	 ERROR: Failed to build gem native extension. 
 

 
    current directory: /Users/paulkim/.rvm/gems/ruby-2.4.2/gems/nio4r-2.1.0/ext/nio4r 
 
/Users/paulkim/.rvm/rubies/ruby-2.4.2/bin/ruby -r ./siteconf20171203-22631-czj48g.rb extconf.rb 
 
checking for unistd.h... yes 
 
checking for sys/select.h... yes 
 
checking for poll.h... yes 
 
checking for sys/epoll.h... no 
 
checking for sys/event.h... yes 
 
checking for sys/queue.h... yes 
 
checking for port.h... yes 
 
checking for sys/resource.h... yes 
 
creating Makefile 
 

 
current directory: /Users/paulkim/.rvm/gems/ruby-2.4.2/gems/nio4r-2.1.0/ext/nio4r 
 
make "DESTDIR=" clean 
 

 
current directory: /Users/paulkim/.rvm/gems/ruby-2.4.2/gems/nio4r-2.1.0/ext/nio4r 
 
make "DESTDIR=" 
 
compiling bytebuffer.c 
 
compiling monitor.c 
 
compiling nio4r_ext.c 
 
In file included from nio4r_ext.c:7: 
 
./../libev/ev.c:488:48: warning: '/*' within block comment [-Wcomment] 
 
/*#define MIN_INTERVAL 0.00000095367431640625 /* 1/2**20, good till 2200 */ 
 
              ^
 
./../libev/ev.c:1068:26: warning: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long long') to 'unsigned int' [-Wshorten-64-to-32] 
 
    return ecb_popcount32 (x) + ecb_popcount32 (x >> 32);

+0

這只是顯示一些警告 - 沒有什麼應該是致命的。關於sys/epoll.h的行只是信息性的(它檢查哪些功能可用,maoll上不存在epoll) –

+0

是否安裝了Xcode及其開發人員命令行工具?您是否至少打開了一次Xcode並接受了許可證? – spickermann

+0

https://stackoverflow.com/questions/8389301/os-x-rails-failed-to-build-gem-native-extension#12229945和https://stackoverflow.com/questions/9552292/failed-to-build -gem-native-extension –

沙发
0
0

正是有了高塞拉利昂和xCode.I一個問題,第一重新格式化我的機器埃爾卡皮坦,也沒有安裝Rails的問題。然後在另一臺機器與高山我也有問題與Rails。

更新到xCode 9.2後,我成功安裝了Rails 5.1.4。

謝謝大家。