Hi all, my first question here.
Let say I have the following code in application_helper.rb
def do_something
if action_name == 'index'
'do'
else
'dont'
end
end
which will do something if called within index action
Q: How do I rewrite the helper spec for this in application_helper_spec.rb to meet simulate a call from 'index'...
Hi all there,
I have a loop (for item in @dataset) and I want, in each iteration, to get different data from another table and make some operations that will be printed in the view. I cant't get this data from the dataset used in the loop.
How can I do this according to MVC? I can put the code into the loop, in the view, but I think it...
So with ruby being ushered in as the new programming messiah, I'm wondering if anyone has preferences based upon ease of use, resources needed to run, usability and ease of customization.
is there a better of the two?
...
I've got three (relevant) models, specified like this:
class User < ActiveRecord::Base
has_many :posts
has_many :comments
has_many :comments_received, :through => :posts, :source => :comments
end
class Post < ActiveRecord::Base
belongs_to :user
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :user
be...
So I have a User model that :has_many other models like Documents, Videos, Posts and the like. My question arises when I execute a "do" block from the User model like so:
has_many :posts do
def recent
find(:all, :order => 'created_at desc', :limit => 12)
end
end
This just lets me call something like user.posts.recent t...
I've been doing some simple rails Apps lately. I know ruby quite well, but when I started doing things "the rails way" I noticed that some things were done "just because" and It's hard for a (rails) newbie to know what does the code do.
Has rails missed the point and turned into some kind of 4th generation language? I mean, you HAVE to ...
Is it possible to retrieve the CPUID and MAC address of a client machine from a Ruby on Rails application?. Are there any plugins available for this?
...
In my models, there are lots of attributes and methods that perform some calculation based on the model instance's attributes. I've been having the methods return nil if the attributes that the calculations depend on are nil. As a consequence of this design decision, I'm doing a lot of nil checks before displaying these values in my vi...
First a bit of background.
I have been working on the MS platform for my entire development career. Up until 2 weeks ago, I had never booted any other OS than 98/XP/Vista. I started using VSS long long ago, and made the change to SVN about 2 years ago. With SVN I use TortiseSVN and use the standard branch/tag/trunk setup.
My projects ...
Hi, I've written a rails app that follows the regular directory structure (model code in models, controller code in controllers).
But I'm now working on a new feature and for that I have written some (what I would call) "service" code.
The new feature is to import some data into the system, at the moment it's two classes to do the impor...
Given the following, how could I insert rows in my db? (Or what should I correct in my schema?)
Models:
class Item < ActiveRecord::Base
has_many :tran_items
has_many :transactions, :through => :tran_items
end
class TranItem < ActiveRecord::Base
belongs_to :item
belongs_to :transaction
end
clas...
Up till now all my programming experience has been desktop development (mostly C/C++ with OpenGL/DirectX) but I'm interested in trying my hand at some web dev.
The two directions I'm considering are Ruby on Rails and ASP.net.
Which is most widely used?
Which would be a more marketable skill to have?
Thanks!
...
What's the best way to run scheduled tasks in a Rails environment? Script/runner? Rake?
...
I would like to make my application somewhat REST compliant. I am using Rails on the backend and GWT on the frontend. I would like to do updates and deletes. I realize I can do something like mydomain.com/:id/delete (GET) and accomplish the same thing. However, as I stated previously, I would like to have a REST compliant backend. T...
Does anyone know of any method in Rails by which an associated object may be frozen. The problem I am having is that I have an order model with many line items which in turn belong to a product or service. When the order is paid for, I need to freeze the details of the ordered items so that when the price is changed, the order's totals a...
Let's assume I have a model called "product." Let's assume that product has three fields. These fields are 'name' (type string), 'cost' (type integer), and 'is_visible' (type bool).
1) How can I do a search query using the Rails "find" method (if there is another method, that's fine) so that I can search for all products with a cost g...
Hi all,
I have two tables:
Client(id,name,...)
Purchase(id,item,date,client_id,...)
They have their respective Model, with their validations. What I need is to create a new client with a new purchase, all into the create method of Client controller. Something like this:
def create
@client = Client.new(params[:client])
respond_t...
In a previous question about overriding Time.now, I was working toward a solution of faking clock synchronization across all machines connecting to a given database. Overriding Time.now seemed the best way for the approach I was taking, however:
It appears as though I could get the result I was after via a much simpler line. If I can ...
I'm looking to develop a website that will be fairly database intensive and that will be playing quite a few videos. My question is this: I don't have any experience as a programmer and I'm trying to figure out whether or not I should learn Ruby on Rails or Flex...or both. I have several people that are working on this project with me th...
I'm currently using Rcov to get C0 code coverage analysis for a rails project that I'm working on.
However, those results are practically meaningless- I have 100% coverage according to rcov (as it only covers C0 analysis) and I've barely written half the test cases for the functionality that exists thus far.
I'm used to the useful resu...