What should I render when destroying a record?

For a delete request, http status code 200 or 204 implies resource deleted successfully. 9.7 DELETE A successful response SHOULD be 200 (OK) if the response includes an entity describing the status, 202 (Accepted) if the action has not yet been enacted, or 204 (No Content) if the action has been enacted but the response … Read more

Using turbolinks in a Rails link_to

Edit for Rails 5+: @ManishShrivastava correctly pointed out the different syntax needed for Rails 5 as shown in Joseph’s answer. <%= link_to(‘Giraffe’, @giraffe, data: { turbolinks: false }) %> For Rails 4 and below Originally I thought you needed to use the hash rocket syntax for the symbol but that isn’t the case. You can … Read more

POSTing raw JSON data with Rails 3.2.11 and RSpec

As far as I have been able to tell, sending raw POST data is no longer possible within a controller spec. However, it can be done pretty easily in a request spec: describe “Example”, :type => :request do params = { token: 0 } post “/user/reset_password”, params.to_json, { ‘CONTENT_TYPE’ => ‘application/json’, ‘ACCEPT’ => ‘application/json’ } … Read more

Factory already registered: user (FactoryGirl::DuplicateDefinitionError)

The gem factory_girl_rails should be required in the spec_helper.rb rather than the gemfile – it is possible that you are requiring FactoryGirl twice which is why you are getting the duplicate. Try this in your gem file: group :test do gem “rspec” gem ‘factory_girl_rails’, :require => false end Then make sure that factory girl is … Read more

ruby on rails how to deal with NaN

NaN is instance of Float. Use Float#nan? method. >> nan = 0.0/0 # OR nan = Float::NAN => NaN >> nan.class => Float >> nan.nan? => true >> nan.is_a?(Float) && nan.nan? => true >> (nan.is_a?(Float) && nan.nan?) ? 0 : nan => 0 UPDATE NaN could also be an instance of BigDecimal: ((nan.is_a?(Float) || nan.is_a?(BigDecimal)) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)