I'm attempting to sum daily purchase amounts for a given user. @dates is an array of 31 dates. I need the find condition to compare a date from the array to the created_at date of the purchases. What I'm doing below compares the exact DateTime for the create_at column. I need it to look at the day itself, not the DateTime.
How can I wr...
hello!
i have a user and an admin role in my project. i created my authentification with devise, really nice and goot tool for handling the authentification. in my admin role i don´t have any confirmation or something like that. it is really simple and doesn´t make problems. but in my user model i have following things:
model:
devise ...
Say I have two models, Apples and Oranges, and they are both associated with a description in a Text model. Text is a separate class as I'd like to keep track of the different revisions. Is the following correct? Is there a better way to do this?
[Apple]
has_one :text, :as => :targit, :order => 'id DESC'
has_many :revisions, ...
Hi,
I have a sql script file that upon import creates a table in a MySQL database and fills it with 2800 record. These are all the postal codes for the country Belgium.
Now I would like to make a Ruby on Rails database migration file from this. Any idea how I can do this?
Maybe there is a way around? Telling in a database migration fi...
I have a model for which I want to retrieve the next record(s) and previous record(s). I want to do this via a named_scope on the model, and also pass in as an argument the X number of next/previous records to return.
For example, let's say I have 5 records:
Record1
Record2
Record3
Record4
Record5
I want to be able to call Model.p...
Hey Guys -
I'm trying to find an easy way(without having to write any plugins or overrides to Rails) to generate an absolute url to a rails application being in a subdirectory. This url is going to be generated for theme images, not links, so I can't url link_to or url_for. Here's an example of what I want to do:
<%= theme_image("delet...
Is it possible to override the to_sentence method just for one model in my rails application?
More generally, how do I modify methods for an Array of my models?
...
Using rails3 - I have a project with many tasks. I want to use javascript to build the UI for each task. I figured I could display those tasks on the projects show page by rendering a javascript partial for each. I can't get 'tasks/show' to see tasks/show.js.erb Any ideas?
In projects/show.html.erb
<div id="tasks">
<%= render(:partial...
I've been trying to follow along in the RSpec book, (I'm new to all of this) and I have what appears to be some kind of versioning issue. If I try and run some simple scenarios, I get this error:
can't activate test-unit (= 1.2.3, runtime) for [], already activated test-unit-2.0.7 for [] (Gem::LoadError)
/Users/jeffdeville/.rvm/ru...
I currently have a form like this:
<% form_for @stem, :html => {:multipart => true} do |f| %>
<%= f.file_field :sound %>
<% end %>
This outputs (essentially):
<form method="post" id="new_stem" class="new_stem" action="/stems">
<input type="file" size="30" name="stem[sound]" id="stem_sound">
</form>
However I'm planning to use jQuer...
Can someone shed light on how to setup by_star gem: https://rubygems.org/gems/by_star?
I ran ruby script/plugin install git://github.com/radar/by_star.git.
However, when I went to call a by_star method in one of my models from console, I got an undefined method error.
Do I need include or require statement? Could I be missing depende...
I am having trouble building a gem. When I run rake it gives the the following error message:
You need to install rspec in your base
app
I'm not completely certain what I should be doing to fix this. I have double checked that rspec is, in fact installed. Any help would be appreciated.
...
Is there a compact way with ActiveRecord to query for what id it's going to use next if an object was going to be persisted to the database? In SQL a query like this would look something like:
SELECT max(id) + 1 FROM some_table;
...
I have multiple coupons on a page and I'm trying to get comments to work on each coupon. So for each coupon i have a comments form. Im using jQuery + Ajax to accomplish this. Here's what my code looks like.
Coupon Page
<p>Comments:</p>
<% form_for(@comment) do |f| %>
<%= f.label :body %><br /><%= f.text_field :body, :size => "24...
More and more I'm putting all of my code in models and helpers concerning MVC.
However, sometimes I'm not sure where to organize code. Should it go into the model or should it go into a helper. What are the benefits of each. Is one faster or are they the same. I've heard something about all models getting cached so it seems then like th...
I need a SQL query that returns results matched by EITHER of the following SQL queries:
Query 1:
SELECT "annotations".* FROM "annotations" INNER JOIN "votes" ON "votes".voteable_id = "annotations".id AND "votes".voteable_type = 'Annotation'
WHERE (votes.vote = 't' AND votes.voter_id = 78)
Query 2:
SELECT "annotations".* FROM "annota...
I am new to RoR, any help would be greatly appreciated :)
I have a basic scaffolding CRUD app to add customers.
I am trying to search by first_name or last_name fields.
The error that I am getting is:
NoMethodError in Clientes#find
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The err...
I've got a model creation form in rails which I also have returning JSON through ajax.
My code so far look like:
$('#new_stem').ajaxForm({ //#new_stem is my form
dataType: 'json',
success: formSuccess
});
function formSuccess(stemObj) {
//does stuff with stemObj
}
And I have a multipart form with a file uploader (but I'm not su...
I'm brand new to Rails, so bear with me.
I have 3 models: User, Section, and Tick.
Each section is created by a user. My guess with this association:
class Section < ActiveRecord::Base
has_one :user
end
Next, each user can "tick" off a section -- only once. So for each tick, I have a section_id, user_id, and timestamps. Here's ...
I have a table of events (in a sqlite3 database for what it's worth) with a column called "when" that contains a timestamp detailing precisely when the event that particular row denotes is set to occur. Right now, I have
@events = Event.find(:all)
in my controller and I am using template helper methods to calculate where to place eac...