我错误地将列命名hased_password为hashed_password.
如何使用迁移重命名此列来更新数据库架构?
我正在使用Ruby on Rails 3.1预发行版.我喜欢使用PostgreSQL,但问题是安装pggem.它给了我以下错误:
$ gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/home/u/.rvm/rubies/ruby-1.9.2-p0/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** 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 …Run Code Online (Sandbox Code Playgroud) postgresql ruby-on-rails pg ruby-on-rails-3 rails-postgresql
我有一个充满数据的开发Ruby on Rails数据库.我想删除所有内容并重建数据库.我正在考虑使用类似的东西:
rake db:recreate
Run Code Online (Sandbox Code Playgroud)
这可能吗?
要向Hash添加新对,我会:
{:a => 1, :b => 2}.merge!({:c => 3}) #=> {:a => 1, :b => 2, :c => 3}
Run Code Online (Sandbox Code Playgroud)
是否有类似的方法从哈希删除密钥?
这有效:
{:a => 1, :b => 2}.reject! { |k| k == :a } #=> {:b => 2}
Run Code Online (Sandbox Code Playgroud)
但我希望有类似的东西:
{:a => 1, :b => 2}.delete!(:a) #=> {:b => 2}
Run Code Online (Sandbox Code Playgroud)
重要的是返回值将是剩余的哈希值,因此我可以执行以下操作:
foo(my_hash.reject! { |k| k == my_key })
Run Code Online (Sandbox Code Playgroud)
在一条线上.
我添加了一张我认为我需要的表格,但现在不再计划使用它了.我该如何删除该表?
我已经运行了迁移,因此该表位于我的数据库中.我认为rails generate migration应该能够解决这个问题,但我还没弄清楚怎么做.
我试过了:
rails generate migration drop_tablename
Run Code Online (Sandbox Code Playgroud)
但那只是一个空的迁移.
在Rails中删除表的"官方"方法是什么?
即删除它创建的所有文件并回滚所做的任何更改?不一定是db,但更多的是配置文件.
例如,自动删除在routes.rb文件中删除的模型/控制器的所有资源映射以及可能已经进行了更改的其他地方?
谢谢.
我在我的应用程序上安装了devise并在我的application.html.erb文件中应用了以下内容:
<div id="user_nav">
<% if user_signed_in? %>
Signed in as <%= current_user.email %>. This cannot be cheese?
<%= link_to 'Sign out', destroy_user_session_path %>
<% else %>
<%= link_to 'Register', new_user_registration_path %> or <%= link_to 'Sign in', new_user_session_path %>
<% end %>
</div>
Run Code Online (Sandbox Code Playgroud)
我跑了rake routes并确认所有路线都有效.
另外,在我的routes.rb文件中我有devise_for :users和root :to => "home#index".
单击"注销"链接时出现以下路由错误:
No route matches "/users/sign_out"
Run Code Online (Sandbox Code Playgroud)
是什么导致错误?
默认情况下,在Rails 3.1(RC1)下,链接在(dev)日志中往往非常冗长:
Started GET "/assets/application.css" for 127.0.0.1 at 2011-06-10 17:30:45 -0400
Compiled app/assets/stylesheets/application.css.scss (5ms) (pid 6303)
Started GET "/assets/application.js" for 127.0.0.1 at 2011-06-10 17:30:45 -0400
Compiled app/assets/stylesheets/default.css.scss (15ms) (pid 6303)
...
Started GET "/assets/default/header_bg.gif" for 127.0.0.1 at 2011-06-10 17:30:45 -0400
Served asset /default/header_logo.gif - 304 Not Modified (7ms) (pid 6303)
Served asset /default/header_bg.gif - 304 Not Modified (0ms) (pid 6246)
Served asset /default/footer_bg.gif - 304 Not Modified (49ms) (pid 6236)
...
Run Code Online (Sandbox Code Playgroud)
我想降低冗长程度或完全禁用它.我假设有一种干净的方法来禁用或减少日志记录的详细程度,方法是在ActiveRecord SQL语句中添加一个environment.rb或development.rb类似的配置行config.active_record.logger = nil …
ruby-on-rails ruby-on-rails-3 sprockets asset-pipeline rails-sprockets
我即将从头开始创建一堆Web应用程序.(请参阅http://50pop.com/code获取概述.)我希望能够从许多不同的客户端访问它们:前端网站,智能手机应用程序,后端网络服务等.所以我真的想要一个每个JSON REST API.
此外,我更喜欢在后端工作,所以我梦想着我完全专注于API,并雇用其他人来制作前端用户界面,无论是网站,iPhone,Android还是其他应用.
请帮我决定采取哪种方法:
一起在铁路上
制作一个非常标准的Rails网络应用程序.在控制器中,执行respond_with开关,以提供JSON或HTML.然后JSON响应是我的API.
亲:很多先例.伟大的标准和许多以这种方式做事的例子.
Con:不一定要API与Web应用程序相同.不喜欢if/then respond_with切换方法.混合两个非常不同的东西(UI + API).
REST SERVER + JAVASCRIPT-HEAVY CLIENT
制作仅限JSON的REST API服务器.使用Backbone或Ember.js直接访问客户端JavaScript,在浏览器中显示模板.
亲:我喜欢API和客户端的分离.聪明的人说这是要走的路.理论上很棒.似乎前沿和令人兴奋.
骗局:没有多少先例.这方面的例子并不多.公共示例(twitter.com)感觉迟钝,甚至转向远离这种方法.
REST服务器+服务器端HTML客户端
制作仅限JSON的REST API服务器.创建一个基本的HTML网站客户端,仅访问REST API.减少客户端JavaScript.
亲:我喜欢API和客户端的分离.但是提供纯HTML5非常简单,而且不是客户密集型的.
骗局:没有多少先例.这方面的例子并不多.框架也不支持这一点.不知道如何处理它.
特别是从经验中寻求建议,而不仅仅是在理论上.
是否有一个替代update_attributes不保存记录?
所以我可以这样做:
@car = Car.new(:make => 'GMC')
#other processing
@car.update_attributes(:model => 'Sierra', :year => "2012", :looks => "Super Sexy, wanna make love to it")
#other processing
@car.save
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我知道我可以@car.model = 'Sierra',但我想在一条线上更新它们.
ruby ruby-on-rails ruby-on-rails-3 ruby-on-rails-4 rails-activerecord