ruby-on-rails

Reversing a hash

I had taken from the database and sorted it according to the position. Then I had put the necessary datas into a Hash. After putting the data in hash and I printed the hash. But the result is in reverse order. So I want to reverse the hash. How can I do this? ...

Help with rails active record querying (like clause)

I want my code to do two things that is currently not doing @students = Student.where(["first_name = ? OR middle_name = ? OR last_name = ?", params[:query].split]) Work. (it says im supposed to pass 4 parameters but I want the user to be able to type words and find by those words on each of those fields and return whatever matches) A...

Tests run from command line but not in RubyMine - No tests were found

I am trying to use RubyMine to run the tests in an existing project. Unfortunately, whenever I attempt to do so I receive the message that No tests were found and the bottom of test console output I see the message: Errors running test:units and test:functionals! Empty test suite. Process finished with exit code 1 I have tried runni...

How to set a Prawn::Table::Cell height?

I am using prawn to generate pdfs and I am having problems when settnig the table height, I set the height but nothing happens. I am using like this: mensagem_tabela = msg_nfe + "\n" + msg_numero + "\n" + msg_serie tabela = Prawn::Table tabela = [[Prawn::Table::Cell.new(:text => mensagem_tabela, :height => 5.cm)]] @data = [[Prawn::Table...

protect_from_forgery :secret in Rails 2.3.8

Hi! I started reading Agile Web Development with Rails, its a very good book! I have one question: I store session in database, I want comment out this line in application_controller: protect_from_forgery :secret => '8fc080370e56e929a2d5afca5540a0f7' in rails 2.3.8. its different (# See ActionController::RequestForgeryProtection for d...

Add constraint to route to exclude certain keyword

I am using Rails and I want to use contraint in route to exclude that route if keyword "incident" is anywhere in the url. I am using rails3. Here is my existing routes. match ':arg', :to => "devices#show", :constraints => {:arg => /???/} I need to put something in constraints so that it does not match if word "incident" is there. ...

Calculate number of business days between two days

I need to calculate the number of business days between two dates. How can I pull that off using Ruby (or Rails...if there are Rails-specific helpers). Likewise, I'd like to be able to add business days to a given date. So if a date fell on a Thursday and I added 3 business days, it would return the next Tuesday. ...

Tab should take me to the submit button but it is not

I am using ruby on rails and I have a form with one text field, two drop down fields and one text area. In chrome after entering the title, I can hit tab (not mouse) to go to next field. I can do all the way and I can go to submit button and then cancel. However in firefox a tab from text field takes me to the next text area. It skips ...

Changing name of folder in Rails - Git won't let me add to commit

Referencing the screenshot above, I changed the name of the lowest-level folder in the tree. For example, I changed "Chips" to "chips." Oddly, Git refuses to recognize the following command when I try to add it to the commit: git add public/images/chips/ The only way I can get it to add the file to the commit is by adding an actua...

In a Rails project, we put all constants definition in config/environment.rb and more particular ones in config/environments/development.rb?

Is that the usual convention? The more general constants in config/environment.rb, and more particular ones, such as HOST_NAME for development mode in config/environments/development.rb as localhost:3000, in config/environments/production.rb as www.mygreatwebsite.com, and they will automatically get included into the project? ...

Rails : Return a custom HTTP Response

Hi everyone, I'm using a payment module from Paybox. This module is a CGI script that I execute like a shell command with backticks : `#{Rails.root}/public/cgi/modulev3.cgi [params]` This module outputs a complete HTTP response, including headers and body : Content-type: text/html Cache-Control: no-cache, no-store Pragma: no-cache ...

How to click button outside the form?

As it stays in documentation for click_button: "Verifies that a submit button exists for the form, then submits the form, follows any redirects, and verifies the final page was successful." But how can I click a button outside the form? ...

Routing questions with rails

Hi, I am just starting with rails and I have a very simple case. I have a "home" controller. There is one action 'index' defined in this controller. When I go to ~/home I get an error msg saying: uninitialized constant HomesController (I noticed the singular/plural thing). That's the first thing I don't get (I thought it would automa...

Rendering different controller actions in Rails when using resource-oriented controllers

Say I'm making a Q&A site like StackOverflow. I have two resources: Question and Answer. I'm using default Rails RESTful resource routes, so each resource has its own controller and methods for creating it. In the /questions/show view, I want to allow the user to submit an answer for the particular question. The form will POST to /answe...

Rails out-of-the-box integration testing

I can't seem to find anything except Rails' own documentation on its integration testing platform. Why doesn't anyone use it? How did it die out? What are alternatives? ...

Mocking with rspec and mocha together

For a test suite that's already using mocha for mocking, can new tests be written with rspec mocking? maybe turn that on before(:all) and turn it back to mocha after(:all) I tried changing the Spec::Runner configuration at run-time and that didn't seem to work with mocking ...

Rails : How to build statistics per day/month/year or How database agnostic SQL functions are missing (ex. : STRFTIME, DATE_FORMAT, DATE_TRUNC)

Hi everyone, I have been searching all over the web and I have no clue. Suppose you have to build a dashboard in the admin area of your Rails app and you want to have the number of subscriptions per day. Suppose that you are using SQLite3 for development, MySQL for production (pretty standard setup) Basically, there are two options ...

How can I make the html output from button_to have single quotes instead of double?

I've got this line: <%= button_to 'Post', newpost_path(:type => 'short_note') %> which outputs this: <form method="post" action="/posts/newpost?type=short_note" class="button-to"><div><input type="submit" value="Add" /></div></form>; But I need the output to have single quotes, not double. How can I do this? <form method='post' ac...

Is there standard Rails mechanism to concat all javascript files into public/javascripts/cache/all.js ?

If the file public/javascripts/cache/all.js is removed, and then a webpage is fetched from the rails server, then that all.js file magically reappears in the file system, with a timestamp that is half an hour ago. Is there actually Rails mechanism that regenerates this file or what might be regenerating this file? ...

Custom Inflections not working on rails3?

I'm using Rails (3.0.1) and have the following code in initializers/inflections.rb ActiveSupport::Inflector.inflections do |inflect| inflect.irregular('nursery', 'nurseries') end From the console I'm getting: "nursery".pluralize => "nurseries" "nurseries".singularize => "nurseries" I should be getting: "nurseries".singularize => ...