ruby-on-rails-3

Serving assets is very slow in development

半世苍凉 提交于 2020-01-01 06:34:04
问题 I have a standart rails 3 webapp with the default asset pipeline. All of a sudden, the assets took a very long time to load (my page loads went to ~1-2secs to ~1min). The server response time (/home) is normal, but some .css and .js files are pending for very long (up to 45 seconds). The only few assets that take this long are those provided by gems (eg: modernizr-rails/vendor/assets/javascripts/modernizr.js ) For example, for modernizr.js?body=1 : Headers: Request URL:http://dev.sharewizz

Show name instead of ID in has_many view table

雨燕双飞 提交于 2020-01-01 06:30:23
问题 I have tried a couple other similar posts but am still getting an error. In the Posts model I have a category_id field. I have the following models: #Posts model belongs_to :categories #Category model has_many :posts In the Posts index controller I have: @categories = @posts.Category.find(:all, :order => 'categoryname') In the View I have: <% @posts.each do |post| %> <tr> <td><%= post.category_id %></td> <td><%= @categories.categoryname %></td> <td><%= link_to 'View', post %></td> <td><%=

How to save data with has_many :through

不想你离开。 提交于 2020-01-01 05:44:07
问题 I have many-to-many relationship between Game and Account models like below: class Account < ActiveRecord::Base has_many :account_games, :dependent => :destroy has_many :games, :through => :account_games end class Game < ActiveRecord::Base has_many :account_games, :dependent => :destroy has_many :accounts, :through => :account_games end class AccountGame < ActiveRecord::Base belongs_to :account belongs_to :game end Now I know let's say I want to create a record something like: @account =

Getting NoMethodError (undefined method `name' for nil:NilClass) when creating a new model in Heroku console

早过忘川 提交于 2020-01-01 05:31:11
问题 I just did a push to Heroku and tried doing some testing by adding a model through rails_admin. When I did that I got a generic error page. I went into the logs and noticed this message: NoMethodError (undefined method `name' for nil:NilClass) I then opened heroku console and tried adding the model manually and received the same message when trying to save. NoMethodError: undefined method `name' for nil:NilClass Here is the model: class Board < ActiveRecord::Base attr_accessible :name,

Mongoid and ActiveRecord generators

别说谁变了你拦得住时间么 提交于 2020-01-01 05:23:04
问题 I have both ActiveRecord (MySQL) and Mongoid in my Rails 3.1 application. Everything is fine, excepts all generators uses mongoid to generate models. This way, when i: rails g model user i receive mongoid-like model, but i need ActiveRecord structure and migrations. How can i switch back to AR? 回答1: Mongoid overrides the model generator, but you can switch it back. In config/application.rb you can either add a line if you've already got a block similar to this: config.generators do |g| g

rails 3.1.1 engines - with mountable engines, is it possible to access parent app assets, default layout?

亡梦爱人 提交于 2020-01-01 05:22:16
问题 This is more for experimentation - I am aware that I can do this with --full but I wanted the functionality of namespacing in the app to avoid conflicts The idea is to have a main app - which handles authentication, common items, admin screens etc Then creating engines to add further functionality like crm cms blog wiki forum etc These engines I can pick and choose as I need for whatever kind of app I am building. Is this possible? Is it just the case of applying both --mountable and --full

Adding bootstrap-datepicker-rails to date_select in form

倖福魔咒の 提交于 2020-01-01 05:16:50
问题 So, I have a form that uses 'date-select', which renders three select boxes per used date-select (year, month and day). Instead I want to use datepicker, and I've followed the instructions here. However, I don't have a clue how to actually implement the datepicker in the form in the view. I'm using the following line in application.js... $('.datepicker').datepicker() ...so I guess I need to give the select boxes the class .datepicker? <%= form_for @project do |f| %> <div class="text_field"> <

How to make Delayed_Job notify Airbrake when an ActionMailer runs into an error?

假如想象 提交于 2020-01-01 04:23:08
问题 The DelayedJob docs mention hooks, including an error hook, but only in the context of custom Job subclasses. This similar question (with no answers) says adding the same hook to the mailer class did not work. What's the trick? Update: In general, I'd like to see how to add hooks to jobs that are triggered using the object.delay.action() syntax, where I don't see an obvious link to a ____Job class. 回答1: I was just searching for a solution to this problem too, and I found this gist. I don't

Rails - how do I validate existence of a row referenced by foreign key

◇◆丶佛笑我妖孽 提交于 2020-01-01 04:12:20
问题 Given that the "Rails Way" seems to be not to use foreign key constraints, I'm looking for an alternative that will allow me to validate that the row a foreign key references does in fact exist in TableA before I save an object in TableB with table_a_id. The only resource I've found to do this so far (can't find a link to the blog post it was mentioned in, was dated 2007) doesn't appear to be compatible with Rails 3.2, so can anyone suggest a way of doing this? I'm currently looking at

Rails: What is the location option for in the render method

假如想象 提交于 2020-01-01 04:12:05
问题 Hey I am wondering what the location option for the render method in rails is. The docs here http://guides.rubyonrails.org/layouts_and_rendering.html states: "You can use the :location option to set the HTTP Location header:" But I have no idea why you would do this, or what you would use this for. 回答1: Actually location option is used to redirect to a new resource as part of processing the request. For example, render :xml => post.to_xml, :status => :created, :location => post_url(post) is