我是Rails 4的新手,并且不理解在Rails 4中使用secret_key_baseunder config/secrets.yml.你能解释一下这个概念吗?
此外,当我在生产环境中我的工作,我提示设置secret_key有devise.rb,config.secret_key和secret_key_base.但是,我可以使用该rake secret命令生成一个新秘密.
开发和生产环境有什么区别?
secret_key当我secret_key_base每次生成时添加它时,它是如何匹配新生成的?
如何使用其他服务器保护应用程序?
我已经浏览了许多SO和google帖子来生成has many and belongs to many关联的连接表的迁移,没有任何工作.
所有解决方案都生成一个空的迁移文件.
我正在使用rails 3.2.13,我有两张桌子:security_users和assignments.这些是我尝试过的一些事情:
rails generate migration assignments_security_users
rails generate migration create_assignments_security_users
rails generate migration create_assignments_security_users_join_table
rails g migration create_join_table :products, :categories (following the official documentation)
rails generate migration security_users_assignments security_user:belongs_to assignments:belongs_to
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉如何在两个表之间创建连接表迁移吗?
migration ruby-on-rails jointable ruby-on-rails-3 ruby-on-rails-4
我正在尝试关注Ryan Bates RailsCast#196:嵌套模型表单第1部分.Ryans版本有两个明显的区别:1)我正在使用内置脚手架而不是他正在使用的漂亮,2)我正在运行rails 4(我真的不知道Ryans在他的演员阵容中使用的是什么版本,但它不是4).
所以这就是我做的
rails new survey2
cd survey2
bundle install
rails generate scaffold survey name:string
rake db:migrate
rails generate model question survey_id:integer content:text
rake db:migrate
Run Code Online (Sandbox Code Playgroud)
然后我将关联添加到模型中
class Question < ActiveRecord::Base
belongs_to :survey
end
Run Code Online (Sandbox Code Playgroud)
所以
class Survey < ActiveRecord::Base
has_many :questions
accepts_nested_attributes_for :questions
end
Run Code Online (Sandbox Code Playgroud)
然后我添加了嵌套视图部分
<%= form_for(@survey) do |f| %>
<!-- Standard rails 4 view stuff -->
<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.fields_for :questions do |builder| %>
<div>
<%= …Run Code Online (Sandbox Code Playgroud) 我试图安装一个使用mysql2gem的开源rails 3.2.21应用程序,但是当我尝试运行bundlecommant时,我收到以下错误:
Fetching: mysql2-0.3.18.gem (100%)
Building native extensions. This could take a while...
p
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/Users/my_username/.rvm/rubies/ruby-2.1.2/bin/ruby -r ./siteconf20150614-72129-orqsb7.rb extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Using mysql_config at /usr/local/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
-----
Don't know …Run Code Online (Sandbox Code Playgroud) database.yml的:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: postgresql
encoding: utf8
database: sampleapp_dev #can be anything unique
#host: localhost
#username: 7stud
#password:
#adapter: sqlite3
#database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development …Run Code Online (Sandbox Code Playgroud) 我有一个Rails 4应用程序,我正在尝试使用自定义字体.
我已经关注了很多关于这方面的教程,不知何故它只是不适用于我的应用程序.
我正在使用application.css.less并有以下声明:
@font-face {
font-family: 'HDVPeace';
src: font-url('HDV_Peace.eot');
src: font-url('HDV_Peace.eot?iefix') format('eot'),
font-url('HDV_Peace.woff') format('woff'),
font-url('HDV_Peace.ttf') format('truetype'),
font-url('HDV_Peace.svg#webfont') format('svg');
}
Run Code Online (Sandbox Code Playgroud)
注意:我尝试过使用 url() 而不是 font-url() .前者在控制台上生成404错误,后者似乎根本不做任何事情.在资源下的chrome dev工具中,字体文件不会出现在 文件夹下assets 或任何位置
在我的config/application.rb身上:
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
Run Code Online (Sandbox Code Playgroud)
在我config/environments/development.rb和config/environments/production.rb我都有:
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
config.assets.precompile += %w( .svg .eot .woff .ttf)
Run Code Online (Sandbox Code Playgroud)
我的字体文件位于app/assets/fonts以下文件夹中,并且不包含在...
我错过了什么?
更新:
文件夹结构
app
|----assets
|----fonts
|----HDV_Peace.eot
|----HDV_Peace.svg
|----HDV_Peace.ttf
|----HDV_Peace.woff
Run Code Online (Sandbox Code Playgroud) 因此,在Rails 4中not添加了使用查询的长期所需功能.
Article.where.not(title: 'Rails 3')
Run Code Online (Sandbox Code Playgroud)
是否为or查询添加了类似的支持,或者他们是否计划进行查询.浏览发行说明我找不到任何东西.
显然我试过了
Article.where(title: 'Rails 3').or(title: 'Rails 4')
Run Code Online (Sandbox Code Playgroud)
但这不起作用.
rails plugin install git://github.com/get/Rename.git 将允许我们只重命名rails 3应用程序
是否有任何宝石可用于重命名Rails 4应用程序.
如果没有,建议我更好的重命名方式.
Hi I am using Devise for my user authentication suddenly my new user registration was not working.
this was error I am getting.
ActionController::InvalidAuthenticityToken
Rails.root: /home/example/app
Application Trace | Framework Trace | Full Trace
Request
Parameters:
{"utf8"=>"?",
"user"=>{"email"=>"example@gmail.com",
"password"=>"[FILTERED]",
"password_confirmation"=>"[FILTERED]"},
"x"=>"0",
"y"=>"0"}
Run Code Online (Sandbox Code Playgroud)
this is my registrations controller
class RegistrationsController < Devise::RegistrationsController
prepend_before_filter :require_no_authentication, :only => [ :new, :create, :cancel ]
prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
before_filter :configure_permitted_parameters
prepend_view_path 'app/views/devise'
# GET /resource/sign_up
def new
build_resource({})
respond_with self.resource
end …Run Code Online (Sandbox Code Playgroud) 我想知道如何在运行简单的测试时关闭所有这些警告:
[1] guard(main)>
16:59:46 - INFO - Run all
16:59:46 - INFO - Running all specs
/Users/esjd/.rvm/gems/ruby-2.1.2/gems/rspec-rails-3.0.1/lib/rspec/rails/adapters.rb:124: warning: instance variable @example not initialized
/Users/esjd/.rvm/gems/ruby-2.1.2/gems/rspec-rails-3.0.1/lib/rspec/rails/adapters.rb:124: warning: instance variable @example not initialized
.*
Pending:
HomeHelper add some examples to (or delete) /Users/esjd/ruby/rails/ts3/spec/helpers/home_helper_spec.rb
# Not yet implemented
# ./spec/helpers/home_helper_spec.rb:14
Finished in 0.03601 seconds (files took 7 minutes 48 seconds to load)
2 examples, 0 failures, 1 pending
/Users/esjd/.rvm/gems/ruby-2.1.2/gems/celluloid-0.15.2/lib/celluloid/tasks.rb:76: warning: global variable `$CELLULOID_DEBUG' not initialized
/Users/esjd/.rvm/gems/ruby-2.1.2/gems/celluloid-0.15.2/lib/celluloid/tasks.rb:76: warning: global variable `$CELLULOID_DEBUG' not initialized
/Users/esjd/.rvm/gems/ruby-2.1.2/gems/guard-2.6.1/lib/guard/interactor.rb:64: warning: …Run Code Online (Sandbox Code Playgroud) ruby-on-rails-4 ×10
ruby ×3
devise ×2
duplicates ×1
fonts ×1
jointable ×1
migration ×1
mysql ×1
mysql2 ×1
postgresql ×1
rspec ×1
secret-key ×1