ruby-on-rails-3.1

How to specify order of field to add using migration in Rails 3?

笑着哭i 提交于 2019-12-12 02:12:50
问题 How can I specify after which field I want to add a new column? (I don't want the field added in at the bottom after the timestamps) add_column :users, :is_active, :boolean 回答1: Here is how: add_column :users, :is_active, :boolean, :after => :some_column where :some_column is the name of the column you want to add :is_active after. 回答2: In general, you can't and you shouldn't care. Tables in relational databases don't really have any particular order; that's why you should always specify the

Routes stopped working when upgrading Rails 3.0 to 3.1

↘锁芯ラ 提交于 2019-12-12 02:06:42
问题 I am using Ruby 1.8.7 with Rails 3.1. My application worked fine in Rails 3.0 but when I bumped it up to Rails 3.1.4, all my url helpers broke! After Googling like a mad man the past 2 days, I have given up and the time has come to seek help. I don't believe the problem is with my routes.rb file but something more on the view/helper side. I have the following in my routes.rb: resources :sessions In my homepage view I have the following link_to, which errors out: <%= link_to "Login", new

No “(.:format)” in Rails 3.1 when trying to route site root

房东的猫 提交于 2019-12-12 01:55:32
问题 Since upgrading to Rails 3.1, I've been having a problem with my site's routing. Previously, with Rails 3.0, I was able to do this in my router config: resources :quotes, :path => "" root :to => "quotes#index" That would give me routes like GET /(.:format) and such, which is what I want since the index action of my QuotesController can also return data in JSON, XML and ATOM. Now, since upgrading to Rails 3.1, the routes have been showing up like this: GET / . The (.:format) is gone, and

How to use sass-rails helpers in Ruby?

时光毁灭记忆、已成空白 提交于 2019-12-12 01:49:32
问题 From the Github page it would seem that one can use the Sass helpers ( asset_path , asset_url , image_path etc.) in Ruby but I can't figure out how. I need to set the default_url for a Paperclip attachment and want to use one of my assets from the asset pipeline for that. 回答1: You can use the sass helpers in SCSS files, but you cannot use them elsewhere. In those cases you need to use the regular asset_path and image_tag helpers. 来源: https://stackoverflow.com/questions/7636204/how-to-use-sass

How do I create a named_route_path for a scoped/nested resource in rails 3.1?

末鹿安然 提交于 2019-12-12 01:48:41
问题 This is my route: scope ":username" do resources :feedbacks end When I do rake routes , I get this: feedbacks GET /:username/feedbacks(.:format) {:action=>"index", :controller=>"feedbacks"} POST /:username/feedbacks(.:format) {:action=>"create", :controller=>"feedbacks"} new_feedback GET /:username/feedbacks/new(.:format) {:action=>"new", :controller=>"feedbacks"} edit_feedback GET /:username/feedbacks/:id/edit(.:format) {:action=>"edit", :controller=>"feedbacks"} feedback GET /:username

Rails 3.1: Custom validation message on join table of has_many through relationship?

妖精的绣舞 提交于 2019-12-12 01:47:00
问题 I have a Meal model that has_many :foods, :through => :servings . Meal also: accepts_nested_attributes_for :servings, :allow_destroy => true validates_associated :servings The Serving model has a field called serving_amount and a field called amount_recorded . In the Serving model, I currently use this validation: validates :serving_size, :numericality => {:greater_than => 0}, :if => :amount_recorded? The message returned if the validation fails is terrible. This is compounded by the fact

Autocompleted search form is not working in all pages

孤街醉人 提交于 2019-12-12 01:16:10
问题 When I use autocompleted search form in some pages it is working but for when I click the "Home", "Help" or "Users" links on navbar, I can only use search form without autocompleted feature. layouts/header.html.erb <% if logged_in? %> <%= form_tag users_path, class: "navbar-form navbar-left", method: :get do %> <% if params[:query].present? %> <%= link_to "clear", users_path%> <%end%> <div class="input-group input-group-md"> <%= text_field_tag :query, params[:query], class: "form-control",id:

Rails 3.1.3 unable to access the file inside assets/javascripts folder

好久不见. 提交于 2019-12-12 01:03:43
问题 I have put fancybox (jquery plugin ) inside the assets/javascripts/includes/jquery.fancybox-1.3.4 Before this location i also tried to put it under /vendor/assets/stylesheets/jquery directory. I am getting this weird error & why isn't rails able to get the particular file when its right there. ------------- Development Log ---------------- Started GET "/vendor/assets/stylesheets/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.pack.js" for 127.0.0.1 at 2011-11-25 13:30:42 -0800

RMagick gem in Cloudfoundry?

一个人想着一个人 提交于 2019-12-12 00:25:10
问题 The rails 3.2 app needs RMagick gem. From the support ticket, they say its in private PaaS. But what for apps hosted on cloudfoundry.com itself, not in private PaaS? 回答1: CloudFoundry.com recently added the ImageMagick binaries, which are necessary for libraries such as RMagick to work. The path is /var/vcap/packages/imagemagick/bin/ . For example, to configure the paperclip gem add the following to config/environments/production.rb : Paperclip.options[:command_path] = "/var/vcap/packages

Create a new Rails app with an existing mysql Database

巧了我就是萌 提交于 2019-12-12 00:05:59
问题 I have an existing mysql database set up, and would like to set up a new rails up simply so my client can view and edit the records in the db. How can I set up a scaffold linked to my existing db. The db name is "Products" and has just one table called "pins". Pins tables: +----------------+---------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------------+---------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI