RSpec controller spec is acting like a request spec | Fixed issues |
- RSpec controller spec is acting like a request spec
- Carrierwave - storing file in dynamic public folder
- Need ActiveRecord query to find parent that has specific child record along with others
- Rails Asset Pipeline, SCSS, and Z-Index
- I want to use ES6 with Rails
- End of file reached Error in controller while hitting a web service using Httparty gem
- Rails 4 Query Interface WHERE IN
- Windows, Ec2ServerCreate - Cannot set JSON attributes when running knife from Rails application
- Find key value pair in PostgreSQL's HSTORE
- Nested attributes with tabs (has_many)
- How to see rabbitmq server logs on heroku?
- Rails console can't connect to database but rake tasks can
- Rails query related to polymorphic association
- How to write the below SQL query in rails 3 ActiveRecord?
- In my project controller there is a function "demo" which returns either true or false
- Trying to highlight a substring with JavaScript
- Doorkeeper OAuth2: how to login from sample app with Password Grant flow
- Rails Copying a model with its associations
- Updating Rails from 2.3.8 [on hold]
- Rails Select Most Popular Products
- activerecord PostgreSQLAdapter override sql_for_insert, query, execute and update_sql
- Ruby: Skip element in loop if an exception is raised
- rails4 dependent destroy callback error
- Bulk insert data into rails DB with associations
- Where should I save values that are commonly used in a Rails model
- Database migrations to heroku don't work
- Cancancan block not working
- JS format in the controller
- How can I print data using the puts statement to development.log file in rails?
- How to check all filtered records in Activeadmin?
RSpec controller spec is acting like a request spec Posted: 23 May 2016 07:08 AM PDT
I have a controller spec that looks roughly like this: This lives in spec/controllers/inquiries_controller_spec.rb, so RSpec should not be inferring that it's a request spec based on its location. When I run this spec, I get the following error: Hmm, it seems that spec_helper.rb rails_helper.rb My InquiriesController lives in app/controllers/inquiries_controller.rb, is not underneath a module, and the route is wired up correctly (I verified this by manually visiting it and verifying that it works). The method is indeed named |
Carrierwave - storing file in dynamic public folder Posted: 23 May 2016 07:05 AM PDT I am using Carrierwave 0.5.8 for storing uploaded file. In my app users can upload any file. So I have to maintain folders like "public/uploads/1/", "public/uploads/2/", where 1, 2...etc will be user ids, and these folders will contain files uploaded by user in his corresponding id folder. So I was reading the doc at : Carrierwave github repo and it has some code like : My question is, what is the File.open("Somewhere") ? Where is the second parameter like "r" or "w" ? Isn't it vague for the beginner to understand? "Somewhere" can't be directory because it is "File.open", it will look for the file. If it is a file then what path should I give? I don't know the name of file beforehand. We can get the filename from the file object parama[:file]. Then it means I have to do something like this: Right? That is fine, But there is one another setting/action in file_uploader.rb : So as per the document it will store the files in that particular folder, based on model.id. But then I am confused what I am doing with File.open action? On top of the documentation there is some more code : I guess store_dir action works with this Note: I am just using it as learning purpose. I am confused with which thing doing what: User.new with file.open or AvatarUploader.new with Uploader.store (Which code when to use and where to use). Can anybody explain? |
Need ActiveRecord query to find parent that has specific child record along with others Posted: 23 May 2016 07:04 AM PDT I'm using Ruby on Rails and Postgres and I have three tables: Event, Speaker, and Event_Speaker (the last of which enables a two-way On an individual speaker's I can't seem to come up with an ActiveRecord query that is able to accomplish this latter part. Any ideas? |
Rails Asset Pipeline, SCSS, and Z-Index Posted: 23 May 2016 06:45 AM PDT I have a .scss stylesheet that is being processed through the Rails Asset Pipeline. The code is as follows: When I run this in development, it get compiled to : However, when I deploy to our production environment with It compiles to What's going on? Is there a compass setting that I don't know about or something is SASS or the asset pipeline configuration that tries to be smart about z-indexes and intelligently reduce them? Seems like a smart thing to do, but in this case, I'd like to disable the functionality... |
Posted: 23 May 2016 06:42 AM PDT I want to use ES6 in a Ruby on Rails application. Earlier I was using CoffeeScript and it was compiled to JavaScript on the fly in the Rails application. Similarly I want use ES6 as source and ES5 in the browser. I do not want to use babel to pre-compile the es6 files into es5. I searched for Babel and Rails but did not find any good gems. |
End of file reached Error in controller while hitting a web service using Httparty gem Posted: 23 May 2016 06:39 AM PDT Please help me, I am sending a get request using httparty, sometime it give End of file error, and sometimes it works file without any problem, I am unable to find problem, please help me to resolve the issue. |
Rails 4 Query Interface WHERE IN Posted: 23 May 2016 07:18 AM PDT I can't seem to figure out how to write the following simple SQL using Rails Active Record Query Interface. Note: I've looked at the following link. However, it only specifies a single column in the outer WHERE clause, whereas I need two. Link: subqueries in activerecord Thanks for any assistance. UPDATE Models [ProductSale] [ProductLocation] Relations Please note my DB is in MySQL. |
Windows, Ec2ServerCreate - Cannot set JSON attributes when running knife from Rails application Posted: 23 May 2016 06:29 AM PDT I am able to launch new instance at AWS from Ruby on Rails application ( and I get error:TypeError (no implicit conversion of Symbol into Integer): As soon as I comment this single line, instance is created, registered with chef server and recipe is running. Any suggestion how to set json attributes of first chef-client run? PS Sample code shows constant value for attribute, but actual value would be dynamically created. |
Find key value pair in PostgreSQL's HSTORE Posted: 23 May 2016 07:05 AM PDT Given a table How can I find if a given set of key-value pairs has at least one match in the database? For example, if I supply this array: |
Nested attributes with tabs (has_many) Posted: 23 May 2016 06:24 AM PDT I'm working with tabs lately, and after some experiments, I've decided to adapt one tab to show one or more instancies of one model (Contact). Well, following the steps of fields_for, created some tab-pane, under tab-content that's under the principal. The logic is : Dados Básicos | Endereço | Contatos (Contact 1)(Contact 2)(Contact 3)... After the nav-pills, should be showing the respective Contact, but it show nothing. Is there any problem in routing? (With the #contact-... etc) |
How to see rabbitmq server logs on heroku? Posted: 23 May 2016 06:21 AM PDT What is the command to see rabbitmq server logs on heroku, either from GUI or from CLI? Thanks! |
Rails console can't connect to database but rake tasks can Posted: 23 May 2016 06:44 AM PDT I have a rails app that is using the one click DO image. I can run any of the How can I fix it? The app is working fine. So I think is a Console output: database.yml EDIT Looking around I found that I added On console EDIT 2
|
Rails query related to polymorphic association Posted: 23 May 2016 06:21 AM PDT I'm trying to find a query through which I can pull the records from the database... Below is the example Can I write any single query, where I can pull all the events of a specific apple and all the events of the bananas related to that specific apple. |
How to write the below SQL query in rails 3 ActiveRecord? Posted: 23 May 2016 05:50 AM PDT Is there any way to run main/subset query in the database side through Active::record (Rails 3). I don't want run the first_result(First db query) and the order by on the top of the result(Second db query). I tried the below: |
In my project controller there is a function "demo" which returns either true or false Posted: 23 May 2016 05:43 AM PDT I am using protect_from_forgery in application controller. I want to disable forgery when demo return true. can anyone help me with this ? |
Trying to highlight a substring with JavaScript Posted: 23 May 2016 07:13 AM PDT I want to write a JS function which will, within an element (a td), find a substring, and highlight it. It only needs to work for the first occurrence of the substring within the element. I am just trying to highlight some keywords on my blog. Here is what I have tried so far - JavaScript Note the object['highlight'] is an object I have access to in my Ruby on Rails code. HTML When I try to run this code, nothing is highlighted. Can anyone see what I have done incorrectly here ? Thanks |
Doorkeeper OAuth2: how to login from sample app with Password Grant flow Posted: 23 May 2016 06:02 AM PDT I have an API app with Doorkeeper gem as OAuth2 provider. It has applications and users (username and password) as the models. Another applications can intercat with the API only after authentication. Currently my app provides only client_credentials and password flows. How can I implement the authenctication form with username and password in sample application that will interact with the API? Thanks |
Rails Copying a model with its associations Posted: 23 May 2016 05:12 AM PDT This is just a general question about copying a model with its database assoications. What is the proper strategy for copying? what happens if for example an association 3 levels deep fails, do you delete the parents as well? |
Updating Rails from 2.3.8 [on hold] Posted: 23 May 2016 05:00 AM PDT I recently purchased a non-profit website written in Ruby on Rails. A developer informed me that it is written in version 2.3.8. I have been told it is not a complex app. Can it be updated to current version - I am receiving conflicting advice. |
Rails Select Most Popular Products Posted: 23 May 2016 05:48 AM PDT I need to get a list of '10 most popular' products. I think that the best way to do this is to use I know what I should do but I don't know how to write it. This is how I would do this in a MySQL:
Update:How I can write the query in Rails? For example: |
activerecord PostgreSQLAdapter override sql_for_insert, query, execute and update_sql Posted: 23 May 2016 04:35 AM PDT I want to update all sql statements for the queries generated for sql_for_insert, query, execute and update_sql for postgres. I'm using rails 3.2.17. Main aim is to change the column names to lower case. I tried to define a class "class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter" in initializers, methods are called over there, but I can't call super as my class isn't extended from any other class. |
Ruby: Skip element in loop if an exception is raised Posted: 23 May 2016 06:45 AM PDT I have the following method: To its purpose: It fetches a value for a given While this works fine I get an error from Rubocop that says:
Googling that error leads me to http://www.rubydoc.info/gems/rubocop/0.36.0/RuboCop/Cop/Lint/NextWithoutAccumulator where it says to not omit the accumulator, which would result in a method looking like this: The problem is, that this change breaks the otherwise working method. Any ideas on how to tackle that? Update: Demonstrational example: |
rails4 dependent destroy callback error Posted: 23 May 2016 04:02 AM PDT I have a The following code throws an |
Bulk insert data into rails DB with associations Posted: 23 May 2016 05:48 AM PDT I wanted to copy and bulk insert data to database (using bulk_insert GEM), so I tried the following: Now, here SAVING But, this only saves the sections but not it's associations. How can I save associations(questions) as well. EDIT Now, I came across this https://github.com/zdennis/activerecord-import/wiki GEM and I'm trying the Multi-Level Example, still questions are not saved. Any ideas? |
Where should I save values that are commonly used in a Rails model Posted: 23 May 2016 03:43 AM PDT Assuming that there is a To get standard score, I need to calculate standard deviation by using But I don't know where should I save the value that is used commonly from all instance of the model. I found that we should avoid to use class variable in rails. Why should we avoid using class variables @@ in rails? Where and how should I save the value? |
Database migrations to heroku don't work Posted: 23 May 2016 03:41 AM PDT I've been trying to migrate my database to heroku, without success. I have added a few more users to my database and when trying to log them in with email address and password on my heroku app, I get invalid email/password error, even though this works perfectly fine on my local server. NO errors at all when doing all the steps described below. As suggested in a previous post, I've tried the following:
After I run this I get:
I've also checked my .sqlite3 file to check that the new users actually exist in the database. I've also tried this: I've also updated my gemfile.lock. My gems in dev & production: Note: I run bundle install --without production, however this is how I've always been using it, and the login data works for some of the users i've created in the past. Also I'm using rails 4.2.2. |
Posted: 23 May 2016 03:53 AM PDT I'm currently using Cancancan for my authorization. I have models As you can see, assets is deeply nested with a many-to-many association in its ancestry. To make sure a However, as it stands any user can go into any company's What might I be missing? Thanks in advance! |
Posted: 23 May 2016 03:20 AM PDT Let's assume I have a controller action that whenever you try to access it via a js format, I want to render nothing. When you access the endpoint via html or JSON, it works just fine. When you try to access it via JS it doesn't work. However, it does actually execute the block, because if I add a However, this does work: So what's the difference between the two? EDIT As a human mentioned below, what's the actual error? So, in this particular case, it raises a |
How can I print data using the puts statement to development.log file in rails? Posted: 23 May 2016 05:26 AM PDT When I write |
How to check all filtered records in Activeadmin? Posted: 23 May 2016 03:38 AM PDT I've filtered some user's records by criteria. Now I want to send an email for all of them, not only for users that are on first page. How to check all filtered users? Something like: |
You are subscribed to email updates from Newest questions tagged ruby-on-rails - Stack Overflow. To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 1600 Amphitheatre Parkway, Mountain View, CA 94043, United States |
No comments:
Post a Comment