ruby-on-rails-3.1

Javascript is cached in development mode with asset pipeline

我怕爱的太早我们不能终老 提交于 2019-12-03 05:14:36
I recently upgraded my application to rails 3.1 and generally everything seems to be working but one thing is driving me insane. I have 2 main js files, we'll call them, application.js and main.js. application.js has my manifest stuff in it and is loading in main.js. That's working fine. My problem is when i'm in development mode and i make a change to main.js, then refresh the page the site doesn't pick up the change. In order to pull in the change I have restart the rails server. I have debug mode turned on in development, but I'm wondering if there's another setting i'm missing? Anyone run

Rails: how to disable before_destroy callback when it's being destroyed because of the parent is being destroyed (:dependent => :destroy)

╄→尐↘猪︶ㄣ 提交于 2019-12-03 04:55:39
I have two classes: Parent and Child with Child: belongs_to :parent and Parent has_many :children, :dependent => :destroy The problem is that I want to check that there is always at least one child present, so I have a before_destroy method in Child that abort the destroy if it is the only child belonging to its parent. And, if I want to destroy the parent, it will call the before_destroy callback on every child, but when there is one child, it will abort the destroy, so the parent will never get destroyed. How can I tell the child to call the before_destroy callback only if it's not being

How do I setup/use ruby on rails snippets and autocomplete in sublime text 2?

随声附和 提交于 2019-12-03 04:33:03
问题 I would appreciate if someone could direct me to a website that shows how to do this.. Can't seem to find anything decent enough via google. This will be the first time I'm doing this kind of thing with a text editor.. It has got to the stage where typing out things like <%= %> is getting old and slow. I've got a rails snippet package and also ryan-on-rails package installed. Just confused with how to start using them. I'm on max osx - snow leopard Kind regards Update This helped me out. http

Best place to store model specific constants in rails 3.1?

老子叫甜甜 提交于 2019-12-03 03:47:10
问题 I have a field type in a model called user which is an int in the db. The value of the int speficies the type of store it is. Example: 0 = mom 1 = dad 2 = grand mother and so on I have several other fields like this so it's overkill to create association tables. Instead of checking for those int values over the place in conditional statements in model and controller logic, is there a place in rails to store these constants. So that I could do this from my models and controllers? if myuser

Assets pipeline when updating to Rails 3.1 on Heroku

岁酱吖の 提交于 2019-12-03 03:45:41
I've just upgraded my app on Heroku from Rails 3.0 to 3.1, and I'm trying to make the assets pipeline work. The main issue is that I can read from the heroku log the following kind of lines, for every asset: 2011-09-03T16:35:28+00:00 app[web.1]: cache: [GET /assets/border-a3c571a354b9381740db48aeebfaa63a.jpg] miss If I understand the pipeline correctly, this should not be "miss" for every request I make from a browser, but it should be found in the cache. Reading the Heroku docs you can find this explanation: Rails 3.1 provides an assets:precompile rake task to allow the compilation penalty to

Rails: about yield

ⅰ亾dé卋堺 提交于 2019-12-03 03:34:28
问题 I saw some code in a Rails v2.3 app. In layout/car_general.html.erb (this view is called by a method in cars_controller) , I saw the code: <body> <%= yield %> <%= javascript_include_tag 'jquery-1.4.2.min' %> <% javascript_tag do %> <%= yield :jstemplates %> var some_car = new Object; <%= yield :some_car %> <% end -%> </body> Two questions to ask: Where can I find the yield content of the first <%=yield%> under <body> . Is it a rails specific way to include js code in a view by using <%= yield

Heroku is not pre-compiling my assets to prepare my app for asset pipeline

大城市里の小女人 提交于 2019-12-03 03:22:42
I'm having a bit of trouble getting my asset pipeline setup working with Heroku/Cedar using Rails 3.1.1 I've pushed my application and it launches successfully but there was no message that said "Preparing asset pipeline" and no static assets are being served up. No JS, CSS, or images are able to be found as there is no slug compilation time or runtime asset compilation being done. Any help would be greatly appreciated. They describe what should happen during deployment at this link which I'll summarize below: With a Rails 3.1 application on Heroku Cedar when you git push heroku your assets

Using RequireJS with a Rails 3.1 app

谁说胖子不能爱 提交于 2019-12-03 03:11:19
问题 Question If you've used RequireJS with a Rails 3 (esp 3.1) app, how is that working for you? Any configuration tricks or other gotchas that I need to watch out for? Background I'm contemplating using RequireJS over the Sprockets-based Asset Pipeline in Rails 3.1, specifically for JavaScript code. I have two motivators for this choice: I want to leverage RequireJS' module management for my JS client-side code. I'd like a precompilation system that can follow my JS library code into other

How to pass a parameter to controller action from view in rails through link_to helper

ぐ巨炮叔叔 提交于 2019-12-03 03:09:53
<%= link_to "Connect", {controller:"home", action:"connectTo"}, id: "btny" %> This is my link_to helper in view. I want to attach a parameter in this link_to tag so that I can get it in the action connectTo . I'm unable to find correct syntax or way to do it, and unable to understand some answers I found on stackoverflow. How can I achieve this? def connectTo #here i want to get the parameter i pass from link_to from view... end Do not use camel case in variable names and method names in Rails. That's not a convention and will bite you later. Use named path when you can, instead of manually

How to use Less in a rails 3.1 application?

旧城冷巷雨未停 提交于 2019-12-03 03:01:54
What is the easiest (is there an easy way?) to use Less (in combination with Sass/Scss) in the rails 3.1 assets pipeline? I want to load a file like foo.css.less like i would do for bar.css.scss I found some wonky solution that does not work for me (haven't tried a lot) : https://github.com/thisduck/ruby-less-js/issues/2 The idea would be to use Twitter Bootstrap in a clean way. Thanks in advance If you only want to use bootstrap, you can do it by including the 'less-rails' and 'less-rails-bootstrap' gems in your GemFile. Then, you can @import bootstrap in your .css.less files: @import