Rails

Rails 4: before_filter vs. before_action

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In rails >4.0.0 generators creates CRUD operations with before_action not before_filter . It seems to do the same thing. So what's the difference between these two? 回答1: As we can see in ActionController::Base , before_action is just a new syntax for before_filter . However all before_filters syntax are deprecated in Rails 5.0 and will be removed in Rails 5.1 回答2: It is just syntax difference, in rails app there is CRUD, and seven actions basically by name index , new , create , show , update , edit , destroy . Rails 4 make it developer

Rails auto-assigning id that already exists

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I create a new record like so: truck = Truck.create(:name=>name, :user_id=>2) My database currently has several thousand entities for truck, but I assigned the id's to several of them, in a way that left some id's available. So what's happening is rails creates item with id = 150 and it works fine. But then it tries to create an item and assign it id = 151, but that id may already exist, so I'm seeing this error: ActiveRecord::RecordNotUnique (PG::Error: ERROR: duplicate key value violates unique constraint "companies_pkey" DETAIL: Key (id)=

Unpermitted parameters in rails 4

匿名 (未验证) 提交于 2019-12-03 02:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I read about collection_check_boxes but I don't understand how can I set the checked values. I have the following model: class Objective edit view: the html checkbox are ok but I don't know how to set the values to objective . I was tried define objective_ids= objectives_ids but nothing happens. In Controller: class ObjectivesController EDIT The log file says Unpermitted parameters: perspective_id, objective_ids 回答1: I solved changing the line params.require(:objective).permit(:name, :code, :description, :objective_ids) to params.require(

rails 3.1.0 ActionView::Template::Error (application.css isn't precompiled)

匿名 (未验证) 提交于 2019-12-03 02:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I made a basic rails app with a simple pages controller with an index function and when I load the page I get: ActionView :: Template :: Error ( application . css isn 't precompiled): 2: 3: 4: Demo 5: <%= stylesheet_link_tag "application" %> 6: <%= javascript_include_tag "application" %> 7: <%= csrf_meta_tags %> 8: app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb__43625033_88530400' Gemfile source 'http://rubygems.org' gem 'rails' , '3.1.0' # Bundle edge Rails instead: # gem 'rails', :git => 'git

test a file upload using rspec - rails

匿名 (未验证) 提交于 2019-12-03 02:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to test a file upload in rails, but am not sure how to do this. Here is the controller code: def uploadLicense #Create the license object @license = License.create(params[:license]) #Get Session ID sessid = session[:session_id] puts "\n\nSession_id:\n#{sessid}\n" #Generate a random string chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a newpass = "" 1.upto(5) { |i| newpass 'show', :id => @license.id end I have tried this spec, but it doesnt work: it "can upload a license and download a license" do file = File.new(Rails.root

Rails 4 + simple_form and jQuery UI. Datepicker is not working via turbolinks

匿名 (未验证) 提交于 2019-12-03 02:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have this form which calls datepicker: ... ... Simple_form wrapper: app/inputs/datepicker_input.rb class DatepickerInput attribute_name.to_s + "-alt"}) end end When the page is loaded from scratch ( $(document).ready event ), the following html is generated: However, when the page is loaded with turbolinks (from side nav bar, "page:load" event), the rendered HTML is the following: Of course, I can simply add hasDatepicker class in .html.erb or in application.js file, but I wonder if it's possible to achieve it with Rails functionality. 回答1

Ruby on Rails, Paperclip, Amazon AWS S3 &amp; Heroku

匿名 (未验证) 提交于 2019-12-03 02:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I try for two days to make my all web site work on the internet through Heroku and Amazon AWS S3 ( to store my images ) but ... I can't make it ! To make it simplier, I would like to use Heroku and Amazon AWS S3 with paperclip just to upload a picture and show it. I followed a lot of tutorial but, this one sum up all I did : https://devcenter.heroku.com/articles/paperclip-s3 The upload system work well with the basic storage in local but if I follow the tutorial and put this code in my environment I have errors config . paperclip

Invoking a large set of SQL from a Rails 4 application

匿名 (未验证) 提交于 2019-12-03 02:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a Rails 4 application that I use in conjunction with sidekiq to run asynchronous jobs. One of the jobs I normally run outside of my Rails application is a large set of complex SQL queries that cannot really be modeled by ActiveRecord. The connection this set of SQL queries has with my Rails app is that it should be executed anytime one of my controller actions is invoked. Ideally, I'd queue a job from my Rails application within the controller for Sidekiq to go ahead and run the queries. Right now they're stored in an

Bundler could not find compatible versions for gem “railties” for Rails 4.0.0

匿名 (未验证) 提交于 2019-12-03 02:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to upgrade to Rails 4.0.0, and I changed the gem versions of sass-rails and coffee-rails . I need to resolve this gem conflict between rails and coffee-rails before I can upgrade to Rails 4. When I ran bundle update this is the output I got: $ bundle update Updating git://github.com/pilu/web-app-theme.git Fetching source index from https://rubygems.org/ Resolving dependencies.............. Bundler could not find compatible versions for gem "railties": In Gemfile: rails (= 4.0.0) ruby depends on railties (= 4.0.0) ruby coffee

Capistrano error tar: This does not look like a tar archive

匿名 (未验证) 提交于 2019-12-03 02:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: INFO [050fe961] Running mkdir -p /home/rails/rails- capistrano/releases/20140114234157 on staging-rails DEBUG [050fe961] Command: cd /home/rails/rails-capistrano/repo && ( PATH=/opt/ruby/bin:$PATH GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/rails/git-ssh.sh mkdir -p /home/rails/rails-capistrano/releases/20140114234157 ) INFO [050fe961] Finished in 0.142 seconds with exit status 0 (successful). INFO [2dea2fe5] Running git archive feature/Capistrano | tar -x -C /home/rails/rails-capistrano/releases/20140114234157 on staging-rails DEBUG [2dea2fe5]