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 Sphinx Actionscript Tornado Register | Login | Edit Tags | New Questions | 繁体 | 简体


10 questions online user: 23

6
votes
answers
30 views
+10

Sphinx connection error on search results page in Ruby on Rails application

I have a RoR app with Posgresql as database. I'm trying to setup search functionality by using Sphinx as search engine and Thinking Sphinx gem. I've installed sphinx with mysql and postgresql support, thinking sphinx v3 gem and it's dependencies.

The command

rake ts:index

performs without errors. Log says that I have 20 docs indexed (all my records of Post model). Then I've tried to create controller and view for search results page. Here's the Controller's search action

def search
    @query = Riddle::Query.escape(params[:q])
    @posts = Post.search(@query)
end

And when I try to use @posts variable in search view

localhost:3000/search?q=hello

I have following error.

ThinkingSphinx::ConnectionError in Main#search

Error connecting to Sphinx via the MySQL protocol. Error connecting to Sphinx via the MySQL protocol. Can't connect to MySQL server on '127.0.0.1' (61) - SELECT * FROM post_core WHERE MATCH('hello') AND sphinx_deleted = 0 LIMIT 0, 20; SHOW META

沙发
+50

ts:index任務只存儲Sphinx數據,它不會啟動響應搜索請求的守護進程。您需要運行ts:startrake任務才能實現此目的。

另外:同時ts:rebuild完成所有這些:停止Sphinx(如果它正在運行),索引數據,啟動Sphinx。

you saved my day thanks. – Asnad Atta Nov 11 '15 at 10:25

板凳
+10

思考Sphinx將mysql用於其內部目的,您必須將mysql2gem 添加到您的堆棧中,例如:

gem 'mysql2', '~> 0.3.13'
gem 'thinking-sphinx', '~> 3.1.1'
地板
0

我陷入困境並面臨同樣的錯誤,最後我發現我沒有使用此命令在我的本地系統上安裝“Sphinx”,

sudo apt-get update
sudo apt-get install sphinxsearch

有關安裝的更多詳細信息,請點擊此處

https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-sphinx-on-ubuntu-14-04

確保您還應該在系統上安裝“mysql-server”來創建連接。

我也看了@ blelump的回答是我的第二步。您也應該包含這些寶石,以便與sphinx一起運行。

然後轉到@pat的答案是我的最後一步,當你安裝sphinx它會啟動服務但你需要停止服務運行,

rake ts:index
rake ts:rebuild

這裡是SPHINX。

0
votes
answers
19 views
+10

在視圖中動態加載簡單內容

0

我跟着this tutorial構建一個簡單的功能:點擊一個按鈕加載存儲在部分內容中的內容。我想稍後在不希望使用信息重載視圖的各個地方使用它,以便讓它們保持輕微,但如果需要,則允許用戶訪問信息。在視圖中動態加載簡單內容

繼教程這是代碼:

# in view: knowledge/index.html.haml 

.container 
    .row 
    .col-xs-12 
     = link_to 'Show more info', fetch_adus_path, :remote => true 
     #adus 

-

# in: config/routes.rb 

get '/knowledge/fetch_adus', to: 'knowledge#selected_adus', as: 'fetch_adus' 

-

# my partial: knowledge/_adus_all.html.haml 

%p Content will be added here 

-

# in: knowledge_controller.rb 

def selected_adus 
    respond_to do |format| 
    format.js 
    end 
end 

-

# knowledge/selected_adus.js.haml 

$("#adus").html("#{escape_javascript(render partial: 'adus_all')}"); 

在知識(索引頁) - 當我將鼠標懸停在「顯示詳細信息」瀏覽器表明它應該鏈接到本地??主機:3000 /知識/ fetch_adus但是當我點擊它沒有任何反應。我在控制檯得到一個錯誤:

GET http://localhost:3000/knowledge/fetch_adus 500 (Internal Server Error) jquery.self-bd7ddd393353a8d2480a622e80342adf488fb6006d667e8b42e4c0073393abee.js?body=1:10255

這(點擊後)導致這行代碼:

xhr.send((options.hasContent && options.data) || null);

爲了提供更多的情況下,當我兩次單擊鏈接我得到一個更簡單錯誤:

knowledge/fetch_adus Failed to load resource: the server responded with a status of 500 (Internal Server Error)

導致此軌錯誤頁面:

ActionController::UnknownFormat in KnowledgeController#selected_adus

ActionController::UnknownFormat

Extracted source (around line #25):

respond_to do |format|

我是新來的鐵軌,如果任何人有任何想法如何解決它,或者如果有任何其他方式建立我所描述的功能,我將非常感謝任何建議。

+0

顯示請求發出時的服務器日誌和完整的控制器代碼 – dstull

+0

@dstull我檢查了日誌,發現了什麼問題。在部分文件中,我有一些被註釋掉的代碼,但奇怪的是它導致了模板錯誤。刪除它和兩個js解決方案(escape_javascript和j渲染 - 翻譯成哈姆 - 工作)。不知何故,我沒有檢查日誌。將其添加到我的個人調試場景清單中。非常感謝! – Socha

沙发
0
1

的解決方案是簡單的比預期的。感謝@dstull,我檢查了日誌,發現了什麼問題。在部分我有一些代碼已被註釋掉,但奇怪的是它導致模板錯誤。刪除它和兩個js解決方案(escape_javascript和j渲染 - 翻譯成哈姆 - 工作)。始終檢查日誌是一種很好的做法。

板凳
0
0

看起來像你的知識問題/ selected_adus.js.haml文件

嘗試重新格式化$("#adus").html("#{escape_javascript(render partial: 'adus_all')}");$("#adus").html("<%= j render partial: 'knowledge/adus_all' %>");

+0

感謝@Zubin--看起來這兩種解決方案都是正確的,問題出在其他地方 - 在一個已被註釋掉的代碼中,但仍然導致模板錯誤。 – Socha

0
votes
answers
39 views
+10

的Rails 5.1 button_to幫手產生的查詢字符串,而不是隱藏表單

1

的,這是我第一次嘗試在計算器,所以我請大家多多...的Rails 5.1 button_to幫手產生的查詢字符串,而不是隱藏表單

我想在時尚,以產生一種預覽頁面中的Rails :

  1. 填表
  2. 發送的形式向控制器
  3. 得到一個視圖中顯示您剛剛發送的數據加上你的表單輸入 4按下一個按鈕控制器產生一些額外的數據確認 數據是正確的
  4. 現在保存一切到數據庫。

當前狀態是:我有表單發佈到控制器上的預覽操作,在那裏做我的魔法並呈現預覽視圖。 在該視圖中,我顯示了所有的數據(它們是作爲一個具有嵌套對象集合的對象從控制器出來的)。 驗證後傳回數據,我嘗試使用一個簡單的按鈕。 正如我所瞭解的「button_to」助手,我應該傳遞我的params散列給幫助者,讓我的所有參數都隱藏在一個按鈕窗體中。 但是,出於某種原因,我的按鈕只包含真實性標記的隱藏字段。所有其他參數都附加到表單上操作的查詢字符串中。

我的按鈕代碼:

<%= button_to(:submit, :action => :create, params: @event_registration.as_json(root: true, include: :participants)) %> 

生成的源代碼:

<form class="button_to" method="post" action="/en/event_registrations?event_registration%5Bcreated_at%5D=&amp;event_registration%5Bevent_id%5D=1&amp;event_registration%5Bid%5D=&amp;event_registration%5Bparticipants%5D%5B%5D%5Bbirthdate%5D=2017-12-27&amp;event_registration%5Bparticipants%5D%5B%5D%5Bcountry%5D=DE&amp;event_registration%5Bparticipants%5D%5B%5D%5Bcreated_at%5D=&amp;event_registration%5Bparticipants%5D%5B%5D%5Bemail%5D=&amp;event_registration%5Bparticipants%5D%5B%5D%5Bfirst_name%5D=&amp;event_registration%5Bparticipants%5D%5B%5D%5Bid%5D=&amp;event_registration%5Bparticipants%5D%5B%5D%5Blast_name%5D=&amp;event_registration%5Bparticipants%5D%5B%5D%5Bnickname%5D=&amp;event_registration%5Bparticipants%5D%5B%5D%5Bpostcode%5D=&amp;event_registration%5Bparticipants%5D%5B%5D%5Bupdated_at%5D=&amp;event_registration%5Bupdated_at%5D=&amp;event_registration%5Buser_id%5D=1"><input type="submit" value="submit" /><input type="hidden" name="authenticity_token" value="A/jV9kY3UYSsYeF9j2+JEsL4XPAixGBYtX47shTsIp5XK5Dq2tdZsQz2KrQOzcJP6roHCEROTF+n6cYyu/iICw==" /></form> 

我要去哪裏錯了嗎?

沙发
0
1

這裏的documentationbutton_to

button_to(名稱=零,選擇=零,html_options =零,&塊)

它看起來像你路過params作爲的一部分options。你應該通過它們作爲html_options的一部分。當你將它們傳遞爲options時,你將它們作爲路徑的一部分傳遞給它們。

試試這個:

<%= button_to(:submit, { :action => :create }, params: @event_registration.as_json(root: true, include: :participants)) %> 
+0

完美,謝謝! 有時候,當你盯着你的代碼和文檔太長時間時,你會相當盲目...... – onkeld

+0

完全。多年來,我一直被這種相同的東西咬了很多次。 –

0
votes
answers
24 views
+10

圖片來源不被讀取(rails)

1

我有一個非常簡單的視圖頁面,出於某種原因,它不會抓住我的圖像。起初,我認爲我的路線出現了一些問題,並且他們已關閉,直到我放下整條路線(如下所示)。我仍然遇到和以前一樣的錯誤,但是如果我採用相同的圖像路徑並將其粘貼到Chrome上的選項卡上,我可以查看圖像。圖片來源不被讀取(rails)

%img{:alt => "Testing Image", :type => "image/jpg", :src => 'images/testImage.jpg' 

對於一些未知的原因,控制檯給我說,Chrome瀏覽器不會讓我打開的,但證明我沒瘋一404 (Not Found)

我合法的途徑:File:///Users/tomJohnson/Desktop/myAppProjectName/app/assets/images/testImage.jpg

有沒有人知道我在做什麼錯?我真的會爲此瘋狂。

+0

它通過使用'image_path'或任何其他工作? '%img {alt:'測試圖片',輸入:'image/jpg',src:image_path('images/testImage.jpg')}'? –

+0

所以....我做錯了,如果我嘗試,我得到'資產「images/testImage.jpg」不存在於資產管道中。「但我覺得它更接近 – kdweber89

+0

哦,男人,你是最好!!!非常感謝!!!!! – kdweber89

沙发
0
1

而不是使用一個「正常」的錨標記,並具有處理源代碼的路徑,你可以使用image_tag幫手:

= image_tag 'images/testImage', alt: 'Testing' 

您還可以使用alt屬性作爲方法的選擇,而不是擔心關於資源擴展/格式。

7
votes
answers
28 views
+10

mismatch of schema in thinking sphinx

I'm working with thinking sphinx

    define_index do
        indexes to
        indexes created_on
        has created_on
    end

now while searching on console

    Emaildumps.search 5.day.ago,
    :group_by => 'created_on',
    :group_function => :day

now the error i get is

     Sphinx Daemon returned error: index emaildumps_core: INTERNAL ERROR: incoming-schema mismatch (in=timestamp created_on:32@160, my=timestamp created_on:32@0)

it may be a dumb question but i'm a newbee at sphinx and i can't understand the fundamentals of indexing and searching in it

what am I doing wrong??

so please help me out.

沙发
+70
+50

它可能是相關的,但你不能擁有同名的字段和屬性。所以,我建議別名其中一個(字段更好):

define_index do
  indexes to
  indexes created_on, :as => :created_on_field
  has created_on
end

也就是說,不確定create_on作為一個字段是否有很多價值,但取決於你。

Thanks @pat! It would be good if TS warned about this issue when reading an index file though. :) – bodacious Mar 25 '16 at 15:58

@bodacious github.com/pat/thinking-sphinx/commit/… - just added this commit to the develop branch :) – pat Mar 26 '16 at 1:18

Awesome! Thanks – bodacious Mar 26 '16 at 7:40

0
votes
answers
44 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
40 views
+10

Ruby on Rails和驗證碼

0

我有驗證碼的問題,我按照一個教程:Ruby on Rails和驗證碼

https://github.com/ambethia/recaptcha

而且在我的應用我有下:

- 在文件config/initializers/recaptcha.rb

Recaptcha.configure do |config| 
    config.site_key = Rails.application.secrets.recaptcha_site_key 
    config.secret_key = Rails.application.secrets.recaptcha_secret_key 
    config.proxy = ‘http://www.google.com/recaptcha/api/verify’ 
end 
  • 在文件的Gemfile

    。 。 。

    gem 'bootstrap-sass', '~> 3.3.7' 
    gem 'jquery-rails', '~> 4.3' 
    gem 'devise', '~> 4.2' 
    
    gem 'toastr-rails', '~> 1.0' 
    
    gem 'recaptcha', require: 'recaptcha/rails' 
    gem 'bcrypt' 
    . 
    . 
    . 
    

在文件app /視圖/設計/註冊/ new.html.erb

<div class="row"> 
    <div class="col-md-4 col-md-offset-4"> 

    <h2 class="text-center">Sign up</h2> 
    <br/> 

    <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> 
     <%= render 'shared/devisemes' %> 

     <div class="form-group"> 
     <%= f.text_field :fullname, autofocus: true, placeholder: "Full Name", class: "form-control" %> 
     </div> 

     <div class="form-group"> 
     <%= f.email_field :email, autofocus: true, placeholder: "Email", class: "form-control" %> 
     </div> 

     <div class="form-group"> 
     <%= f.password_field :password, autocomplete: "off", placeholder: "Password", class: "form-control" %> 
     </div> 
     <br/></br> 

     <div class="actions"> 
     <%= f.submit "Sign up", class: "btn btn-normal btn-block" %> 
     </div> 
    <% end %> 

    <hr/> 
    <%= link_to "Sign in with Facebook", user_facebook_omniauth_authorize_path, class: "btn btn-facebook btn-block" %> 
    </div> 
    <div class="form-group"> 
    <%= raw receptcha_tags %> 


    </div> 
</div> 

和日誌顯示下一個:

=> Booting Puma 
=> Rails 5.1.4 application starting in development 
=> Run `rails server -h` for more startup options 
Exiting 
/Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/devise-4.3.0/lib/devise/rails/routes.rb:498:in `raise_no_secret_key': Devise.secret_key was not set. Please add the following to your Devise initializer: (RuntimeError) 

    config.secret_key = '00a17c1ccd9a5dea9b6c845e0e5e46fc29d4e42e82e1146dd5df3b219b05bd7b5304125eb800b7187aa200aa096d3287d8b720f1a034439015ad1f11ffef2d1b' 

Please ensure you restarted your application after installing Devise or setting the key. 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/devise-4.3.0/lib/devise/rails/routes.rb:226:in `devise_for' 
    from /Users/dmuino/Desktop/StJames/config/routes.rb:5:in `block in <top (required)>' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:426:in `instance_exec' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:426:in `eval_block' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:408:in `draw' 
    from /Users/dmuino/Desktop/StJames/config/routes.rb:1:in `<top (required)>' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in `load' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in `block in load' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in `load' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:55:in `block in load_paths' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:55:in `each' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:55:in `load_paths' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:18:in `reload!' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:41:in `block in updater' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/file_update_checker.rb:81:in `execute' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:42:in `updater' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:31:in `execute_if_updated' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/application/finisher.rb:128:in `block in <module:Finisher>' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/initializable.rb:30:in `instance_exec' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/initializable.rb:30:in `run' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/initializable.rb:59:in `block in run_initializers' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `call' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/initializable.rb:58:in `run_initializers' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/application.rb:353:in `initialize!' 
    from /Users/dmuino/Desktop/StJames/config/environment.rb:5:in `<top (required)>' 
    from config.ru:3:in `require_relative' 
    from config.ru:3:in `block in <main>' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.3/lib/rack/builder.rb:55:in `instance_eval' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.3/lib/rack/builder.rb:55:in `initialize' 
    from config.ru:in `new' 
    from config.ru:in `<main>' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.3/lib/rack/builder.rb:49:in `eval' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.3/lib/rack/builder.rb:49:in `new_from_string' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.3/lib/rack/builder.rb:40:in `parse_file' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.3/lib/rack/server.rb:319:in `build_app_and_options_from_config' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.3/lib/rack/server.rb:219:in `app' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:24:in `app' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.3/lib/rack/server.rb:354:in `wrapped_app' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:80:in `log_to_stdout' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:42:in `start' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:135:in `block in perform' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in `tap' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in `perform' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/command/base.rb:63:in `perform' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/command.rb:44:in `invoke' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>' 
    from /Users/dmuino/Desktop/StJames/bin/rails:9:in `require' 
    from /Users/dmuino/Desktop/StJames/bin/rails:9:in `<top (required)>' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/client.rb:30:in `run' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-2.0.2/bin/spring:49:in `<top (required)>' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:68:in `require' 
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:68:in `require' 
    from /Users/dmuino/Desktop/StJames/bin/spring:15:in `<top (required)>' 
    from bin/rails:3:in `load' 
    from bin/rails:3:in `<main>' 

但我檢查它首先看起來不錯,但它不能正常工作。 而我的應用程序工作正常,在配置recaptcha之前,我配置了它不工作。 我不知道是誰的問題,我認爲還有更多的配置,因爲填寫表單並填寫驗證碼時,您需要傳遞一個值來檢查它,而且這個值很好,保存表單。如果此表單錯誤,請不要保存表單並顯示錯誤。

你能幫助我,我是新手,我這樣做是遵循一個過程,現在我想安裝一個驗證碼安全的minimoun

+0

您是否確保您具有對應於Rails.application.secrets.recaptcha_secret_key的值並重新啓動服務器? 打印在軌道控制檯上的輸出 –

+0

我重新啓動服務,我有這些值在'config/secrets.yml' – Diego

沙发
0
0

您需要安裝設計在配置密鑰/初始化/ devise.rb

config.secret_key = 'secret key goes here' 

的更多信息,請閱讀devise。或devise tutorial

+0

我有正確的鑰匙放在'config/secrets.yml'但我沒有文件'config/initializers/devise.rb'中的配置 – Diego

板凳
0
0

我有這樣的config/secrets.yml

shared: 
    recaptcha_site_key: 'site_key here' 
    recaptcha_secret_key: 'secret_key here' 

隨着放在那裏的校正按鍵。

0
votes
answers
19 views
+10

在rails上反應/ react intl

2

我試圖按照本指南爲rails/react_on_rails項目實現i18n; https://github.com/shakacode/react_on_rails/blob/master/docs/basics/i18n.md在rails上反應/ react intl

我得到 「FORMATMESSAGE沒有定義」 的錯誤,所以我可能失去了一些東西,這是我的代碼:

import PropTypes from 'prop-types'; 
import React from 'react'; 
import { IntlProvider } from 'react-intl'; 

import { addLocaleData } from 'react-intl'; 
import en from 'react-intl/locale-data/en'; 
import nb from 'react-intl/locale-data/nb'; 
import { translations } from '../../../libs/i18n/translations'; 
import { defaultLocale } from '../../../libs/i18n/default'; 

// Initizalize all locales for react-intl. 
addLocaleData([...en, ...nb]); 

// set locale and messages for IntlProvider. 
// const locale = method_to_get_current_locale() || defaultLocale; 
const locale = defaultLocale; 
const messages = translations[locale]; 

import { defaultMessages } from '../../../libs/i18n/default'; 


export default class TextMessage extends React.Component { 

    render() { 
    return (
     <IntlProvider locale={locale} key={locale} messages={messages}> 
     { formatMessage(defaultMessages.ActionsYes) } 
     </IntlProvider> 

    ); 
    } 
} 
沙发
0
1

你得到確切的錯誤消息:

FORMATMESSAGE沒有定義

我一直在使用react-intl所以我相信你需要做的首先要注入intl對象。你可以在react-intl文檔中閱讀。試試這個:

import { IntlProvider, injectIntl } from 'react-intl'; 

... 

class TextMessage extends React.Component { 


    render() { 

    return (
     <IntlProvider locale={locale} key={locale} messages={messages}> 
     { this.props.intl.formatMessage(defaultMessages.ActionsYes) } 
     </IntlProvider> 

    ); 
    } 
} 

export default injectIntl(TextMessage); 

我敢打賭,它會工作。這裏

import { IntlProvider, FormattedMessage } from 'react-intl'; 

... 

export default class TextMessage extends React.Component { 
    render() { 
    return (
     <IntlProvider locale={locale} key={locale} messages={messages}> 
     <FormattedMessage {...defaultMessages.ActionsYes} /> 
     </IntlProvider> 

    ); 
    } 
} 
+0

小隨訪,使用的最後一個版本,我再次得到一個錯誤;:

或者更簡單的只是改變這失敗的道具類型:道具'id'在FormattedMessage中被標記爲必需,但其值爲undefined。 – hso

+1

您需要將'id'和'defaultMessage'道具傳遞給'FormattedMessage'。 make'console.log(defaultMessages.ActionsYes)'並檢查它是否有它們。 – Tomasz

0
votes
answers
38 views
+10

紅寶石軌道測試 - 表X沒有列名爲Y

0

我想寫一些基本的Rails測試代碼,使用默認的軌道測試框架。我的應用程序是一個簡單的論壇,在這裏用戶可以發佈主題,發表評論等紅寶石軌道測試 - 表X沒有列名爲Y

我試圖測試論壇(即線程)控制器,那就是:

forums_controller_test.rb

require 'test_helper' 

class ForumsControllerTest < ActionController::TestCase 
test "index should be success" do 
    get :index 
    assert_response :success 
end 
end 

我使用的夾具和我下面這個教程: https://www.youtube.com/watch?v=0wIta0fITzc

這裏是我所有的測試數據中:

comments.yml

comm_one: 
    body: MyText 
    forum_id: 1 

comm_two: 
    body: MyText 
    forum_id: 2 

forums.yml

for_one: 
    title: MyString 
    body: MyText 
    user_id: 1 

for_two: 
    title: MyString 
    body: MyText 
    user_id: 2 

users.yml裏

user_one: 
    user_id: '1' 

user_two: 
    user_id: '2' 

我遇到的問題是,當我在終端運行rake,我得到這個錯誤:

Error: ForumsControllerTest#test_index_should_be_success: ActiveRecord::Fixture::FixtureError: table "users" has no column named "user_id".

不知道您是否需要查看我的遷移文件,但是如果您需要任何其他信息,請告訴我。

我將不勝感激任何意見。

感謝

注:我使用的是色器件寶石爲我的用戶認證。這也用於生成用戶表。

沙发
0
1

我認爲在表中有一個問題,用戶不會有一個user_id列,而只是一個id,如果另一個模型有一個用戶,或者屬於一個用戶,那麼該模型將有一個user_id列來獲取相應的用戶。 看看文檔,以瞭解您的數據庫中必須具有的結構:http://guides.rubyonrails.org/association_basics.html

+1

謝謝你,我改變了,USER_ID ID,而且這導致我解決了這個問題(解決了其他一些問題之後) – User59

板凳
0
1

我設法解決這個問題,首先遵循Tisamu關於用id替換user_id的建議。然後我添加用戶電子郵件到用戶文件,使其如此:

user_one: 
    id: 1 
    email: '[email protected]' 

user_two: 
    id: 2 
    email: '[email protected]' 

這解決了與任何代碼的問題。但我後來接到錯誤消息說此:

Error: 
ForumsControllerTest#test_index_should_be_success: 
ActionView::Template::Error: Devise could not find the `Warden::Proxy` instance on your request environment. 
Make sure that your application is loading Devise and Warden as expected and that the `Warden::Manager` middleware is present in your middleware stack. 
If you are seeing this on one of your tests, ensure that your tests are either executing the Rails middleware stack or that your tests are using the `Devise::Test::ControllerHelpers` module to inject the `request.env['warden']` object for you. 
    app/views/forums/index.html.erb:21:in `block in _app_views_forums_index_html_erb___3974819143402431947_37087120' 
    app/views/forums/index.html.erb:15:in `_app_views_forums_index_html_erb___3974819143402431947_37087120' 
    test/controllers/forums_controller_test.rb:6:in `block in <class:ForumsControllerTest>' 

我通過簡單地添加Devise::Test::ControllerHelpers我的測試文件解決了這個問題,使之像這樣:

require 'test_helper' 

class ForumsControllerTest < ActionController::TestCase 
include Devise::Test::ControllerHelpers # <-- Have to include this 
test "index should be success" do 
    get :index 
    assert_response :success 
end 
end 
0
votes
answers
35 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。

謝謝大家。