ruby-on-rails-3.1

Rails 3.1 link_to not showing confirmation or destroying properly

被刻印的时光 ゝ 提交于 2019-12-01 18:48:31
I've been plowing through the chapters at railstutorial.org and been using Rails 3.1.3 because I'm crazy and/or wanted a challenge. I managed to figure out most version problems easily but this one stumped me for a while. In 10.4.2, Michael Hartl uses the following code to delete users: <%= link_to "delete", user, :method => :delete, :confirm => "You sure?", :title => "Delete #{user.name}" %> It doesn't work properly if you test it in the browser (chrome) and instead sends you to that user page. It is supposed to work if you include this: <%= javascript_include_tag :defaults %> but it fails

Mixed file types with CarrierWave

浪子不回头ぞ 提交于 2019-12-01 15:54:06
I've a CarrierWave uploader that shall accept a variety of file types. Some are image types (e.g. jpg, png) others are not. I would like to create a medium version of the uploaded file with version :medium do process :resize_to_fit => [300, 300] end As this only works for image files, how can I distinguish between images and other types and omit the resizing for non-image files? At the moment CarrierWave tries to process the file regardless of it's type which leads to a MiniMagick processing error if the file is not an image. Sergey Kishenin According to the Carrierwave Docs you can do the

Rails 3.1: Should File Uploads be added to asset pipeline?

青春壹個敷衍的年華 提交于 2019-12-01 15:53:03
问题 I have a rails 3.1 application that allows users to upload pictures. Should these pictures be stored as assets(in app/assets) and therefore be subject to Sprocket overhead(caching, fingerprinting, etc.)? Or should I keep them in public/images and store them outside of the asset pipeline? 回答1: The asset/image is IMHO for structural/design images (background, icons, banners etc). Dynamically added pictures/assets should go in the public directory. 回答2: I've had this trouble and it was a

Rails 3.1 asset pipeline - missing files from public/assets - why isn't this the default?

时间秒杀一切 提交于 2019-12-01 15:49:56
After I deployed my upgraded Rails 2.3.x -> 3.1 (rc4) app to our test environment this afternoon, all of our stylesheets and JavaScript files were returning 404 errors. We had added the rake assets:precompile task to our post-deploy script and it took a while to determine why the assets folder didn't have the pre-compiled files we expected. In the end, the files weren't being compiled because apparently only application.css and application.js (+ non JS/CSS files) are processed by default. We needed to change the following configuration value as follows: config.assets.precompile += %w( *.js *

There is a way to handle `after_save` and `after_destroy` “equally”?

为君一笑 提交于 2019-12-01 15:16:39
I am using Rails 3.1.0 and I would like to know if it is possible to handle after_save and after_destroy callbacks "equally". That is, I need to run same methods for both after_save and after_destroy callbacks. At this time I must handle those callbacks separately even if those accomplish to the same thing: after_save do |record| # Make a thing end after_destroy do |record| # Make the same thing as in the 'after_save' callback end So, there is a way to handle after_save and after_destroy "equally"? Instead of a block give after_save and after_destroy a method name of your model as a symbol.

Rails: HABTM - find all records with no association

心不动则不痛 提交于 2019-12-01 15:02:09
问题 I have 2 models (Workout, Equipment) in a has and belongs to many relationship. If I use Workout.find(:all, :joins => :equipment, :conditions => "equipment.id = 5") it works, but if I use Workout.find(:all, :joins => :equipment, :conditions => "equipment.id = null") it doesn't return the records with no association. Any ideas? 回答1: Give this a whirl; Workout.joins("left join equipments e on workouts.id = e.workouts_id").where("e.id is null") 来源: https://stackoverflow.com/questions/11279317

Rails 3.1 asset pipeline - missing files from public/assets - why isn't this the default?

♀尐吖头ヾ 提交于 2019-12-01 14:55:51
问题 After I deployed my upgraded Rails 2.3.x -> 3.1 (rc4) app to our test environment this afternoon, all of our stylesheets and JavaScript files were returning 404 errors. We had added the rake assets:precompile task to our post-deploy script and it took a while to determine why the assets folder didn't have the pre-compiled files we expected. In the end, the files weren't being compiled because apparently only application.css and application.js (+ non JS/CSS files) are processed by default. We

Ruby on Rails: How can I add a css file with rails project?

邮差的信 提交于 2019-12-01 14:45:00
The application.html.erb file: <!DOCTYPE html> <html> <head> <title>Site</title> <%= stylesheet_link_tag :all %> <%= javascript_include_tag "application" %> <%= csrf_meta_tags %> </head> <body> <%= yield %> </body> </html> I have a file "cake.generic.css" in public/ folder. But when I reload the page the effect of css file is not working. If I see the page view source I see something like this: <!DOCTYPE html> <html> <head> <title>Site</title> <link href="/assets/all.css" media="screen" rel="stylesheet" type="text/css" /> <script src="/assets/jquery.js?body=1" type="text/javascript"></script>

Rails 3.1 Need to do in place editing on an Index page

依然范特西╮ 提交于 2019-12-01 13:53:56
I have an index page with a free form comment field. The Comment field is part of another model that is not associated-- long story, part me, part user. What I need to figure out is what to use to do that. I ran into a problem with Best In Place (here) and am not sure if that is a resolvable path. So, does anyone have a tutorial or advice to point me to regarding doing in place editing for an index? What I wound up doing was: Create a row in the table that was a TextArea and assigned the text area a class: <td class="textcell" id="<%= crb_agenda.key %>"><%= text_area_tag 'comment', if @pdms

Rails initializer that runs *after* routes are loaded?

こ雲淡風輕ζ 提交于 2019-12-01 13:49:20
问题 I want to set a class attribute when my Rails app starts up. It requires inspecting some routes, so the routes need to be loaded before my custom code runs. I am having trouble finding a reliable place to hook in. This works PERFECTLY in the "test" environment: config.after_initialize do Rails.logger.info "#{Rails.application.routes.routes.map(&:path)}" end But it doesn't work in the "development" environment (the routes are empty) For now I seem to have things working in development mode by