Questions tagged «ruby-on-rails»

Ruby on Rails是一个用Ruby编写的开源全栈Web应用程序框架。它遵循流行的MVC框架模型,并以其“配置之上的约定”方法进行应用程序开发而闻名。


5
解析字符串,就好像它是Ruby on Rails中的查询字符串
我有一个像这样的字符串: "foo=bar&bar=foo&hello=hi" Ruby on Rails是否提供将其解析为查询字符串的方法,所以我得到了这样的哈希: { :foo => "bar", :bar => "foo", :hello => "hi" } 还是我必须自己写? 编辑 请注意,上面的字符串不是来自URL的真实查询字符串,而是来自Facebook Connect存储在cookie中的字符串。

1
Rails db:migrate与rake db:migrate
我是新手。我注意到在Rails 5中生成数据迁移时,有些人用rails db:migrate了over rake db:migrate。有人可以解释一下Rails vs rake命令在数据库迁移中的区别吗?这是否意味着在rails 5中过时的rake命令? 非常感谢

8
库未加载:/usr/local/opt/readline/lib/libreadline.6.dylib(LoadError)
我尝试运行我的rails c但由于某种原因,出现此错误: https://gist.github.com/anonymous/166713e8cde860fb188a8dffb98a1563 ᐅ rails c Running via Spring preloader in process 6609 /Users/zulhilmi/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require': dlopen(/Users/zulhilmi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle, 9): Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib (LoadError) Referenced from: /Users/zulhilmi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle Reason: image not found - /Users/zulhilmi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle from /Users/zulhilmi/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `block in require' from /Users/zulhilmi/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency' from /Users/zulhilmi/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require' from /Users/zulhilmi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/completion.rb:10:in `<top (required)>' from /Users/zulhilmi/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require' from …

7
单击link_to帮助器后,Rails,JavaScript无法加载
当我在rails中使用link_to帮助器时,加载JavaScript时遇到了一些麻烦。当我手动输入带有'localhost:3000 / products / new'的URL或重新加载页面时,将加载javascript,但是当我经过如下所示的链接时,jQuery$(document).ready将不会加载到新页面上。 Link_to,当我单击此链接时,javascript无法加载: <%= link_to "New Product", new_product_path %> products.js文件 $(document).ready(function() { alert("test"); }); 任何帮助将非常感激。提前致谢!

2
Rails路线命名空间和form_for
我的routes.rb中有名称空间 namespace :businesses do resources :registration end 我的控制器位于业务/ registration_controller子目录中。 def new @business = Business.new end 在我看来,我想这样做,form_for @business do |f| ...但是出现以下错误: No route matches {:controller=>"businesses", :action=>"create"} 重新启动服务器,我也得到这个: undefined method#<#:0x10339bb20>的“ business_path” 这是我的耙路: home_index GET /home/index(.:format) {:action=>"index", :controller=>"home"} new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"} user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"} destroy_user_session GET /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"} …



4
Rails迁移:检索当前迁移版本的最佳方法
有没有好的方法来检索迁移版本号? 我需要在模型中实现一个方法,该方法在特定的迁移版本之上和之外具有不同的行为。 我发现连接适配器中的假定为_migrated_upto_version正在从数据库检索版本,但找不到其他版本。 背景:我正在尝试从表A中删除两列,想将它们移到表B中,并从表A添加到表B的关联。 在此更改期间,我需要访问这两列。但是在那之后,我想为这些列添加代理方法以实现兼容性。

3
当您的Gemfile需要较旧版本的捆绑程序时,如何“捆绑安装”?
我在一个较旧的具有Gemfile的Rails项目中。我尝试将宝石添加到Gemfile中,bundle install但出现错误: Bundler could not find compatible versions for gem "bundler": In Gemfile: rails (= 3.0.0) ruby depends on bundler (~> 1.0.0) ruby Current Bundler version: bundler (1.1.5) This Gemfile requires a different version of Bundler. 它使用的Rails版本需要bundler〜> 1.0.0,但是我已经安装了1.1.5,并将其用于其他项目。通常我会使用,bundle exec ...但是由于我们正在谈论的是捆绑器,因此它要复杂得多。如何在我的Gemfile中添加gem并bundle install在使用所需的bundler版本时运行?

2
Rails 4中secret_key_base的用途是什么
我是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每次添加新生成的内容时,它如何匹配新生成的内容? 如何通过其他服务器保护应用程序?

18
设计没有密码的更新用户
我想在设计时更新没有密码的用户属性。情况是这样的,如果密码和密码确认字段不为空,那么我需要设计错误,如果它们为空,则需要更新其他用户属性。我怎样才能通过设计做到这一点? 提前致谢!


4
如何在Rails中从名称字符串实例化类?
我们如何在Ruby-on-Rails中从名称字符串实例化类? 例如,我们在数据库中使用“ ClassName”或“ my_super_class_name”之类的格式来命名它。 我们如何从中创建对象? 解: 我自己在寻找它,但没有找到,所以在这里。 Ruby on Rails API方法 name = "ClassName" instance = name.constantize.new 它甚至可以不格式化,我们可以使用用户字符串方法.classify name = "my_super_class" instance = name.classify.constantize.new 当然,这可能不是很“ Rails Way”,但它解决了它的目的。

10
我如何让Haml与Rails合作?
我试图让Haml与我的Ruby on Rails项目一起工作。我是Ruby on Rails的新手,我真的很喜欢。但是,当我尝试添加aplication.html.haml或index.html.haml视图时,我只会收到错误消息。 我使用NetBeans作为我的IDE。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.