I have the following seeds.rb file:
initial_users = User.create(
[
{
:first_name => "Joe",
:last_name => "Smith",
:address1 => "123 Anywhere St.",
:city => "San Francisco",
:state => "CA",
:zip => "12345",
:phone => "123-456-1234",
:password => "password"
},
{
:first_name => "Jane",
:last_name => "Doe",
:address1 => "123 Ma...
how can i call a java class in ruby
...
Hi Guys I run a sinatra application with mongomapper. I have models called Movie(Document) and Cover(EmbeddedDocument).I embed covers into movies using
@movie.covers << @cover
@movie.save
This works great.
when hit @movies.covers I got the array of embedded documents.
But I am not able to destroy the embedded document. I tried someth...
I need to execute this query to find out the next auto_increment value that will be used by MySQL for a particular table.
find_by_sql ["select auto_increment from information_schema.tables where
table_schema = ? and table_name = ? and auto_increment is not null", db_name, tbl_name]
How to invoke this particular query? This works o...
I'm new to Rails and am working with the collection_select method.
I have two fields I'd like to display in my select box:
first_name and last_name
So far, I can only display one or the other, not both.
Here's the code I'm working with:
collection_select(:hour,:shopper_id,@shoppers,:id,"last_name")
Thank you.
...
Is Time.zone.now.to_date equivalent to Date.today?
Another way to put it: will Time.zone.now.to_date == Date.today always be true?
If not, what's the best way to get a Date object corresponding to "now" in the application time zone?
...
I test my application with Cucumber and it worked before I've added auto-detection of locales from WWW browser in application_controller.rb:
before_filter :set_locale
private
def set_locale
xxx = request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first
if xxx.match /^(en|fr)$/
I18n.locale = xxx
el...
Hey folks
I'm looking for an eCommerce framework with as many of the following features as possible.
Categories, sub-categories and product pages (easy, I know!).
ePDQ/Barclays Payment Gateway Support
User can pick Delivery Time Slots. Think online supermarkets, where you pick a time you're in to receive delivery.
Loyalty Schemes. For...
The following hpricot code successfully extracts the STPeriods in the XML on two of my machines (Vista and an Ubuntu server) but fails on another Ubuntu laptop. All machines have Hpricot v0.82
Any ideas? Totally stumped.
Hpricot code:
(doc/"WeatherFeed/Location/WxShortTerm/STPeriod").each do |ham_forecast|
XML file
<?xml version=...
I need to create a row in both tickets and users table... I just need to know how to process in case the transaction fails.
@ticket.transaction do
@ticket.save!
@user.save!
end
#if (transaction succeeded)
#.....
#else (transaction failed)
#......
#end
On a side note I'd just like to thank everyone who participates at stack ov...
I have an Event model with a finish_time field and a form checkbox called whenever. When whenever is checked I want to set finish_time to nil regardless of its value in parameters, when whenever is not checked I want to make sure that finish_time is a valid date before I save it in the database.
Currently I am achieving this using a w...
I'm working on unit tests for my Rails app and have run into the following problem.
I have an Event model with a fixture that boils down to:
concert:
name: Wallflowers
start_at: <%= DateTime.new(1999) %>
In my unit test, I have the following assertion:
assert_equal DateTime.new(1999), events(:concert).start_at
The te...
I'm trying to work with the data in my Rails application from within a separate Ruby script.
I read this forum post in which some people suggest that the best way to work with your data is to encapsulate the database within one application, and then have this application provide an API for working with that data. Because it's apparently...
I have three tables:
Posts
Keywordings
Keywords
Relevant fields in parens.
A Post
has_many :keywordings
has_many :keywords, :through => :keywordings
A Keywording(post_id, keyword_id)
belongs_to :post
belongs_to :keyword
A Keyword(name)
has_many :keywordings
has_many :posts, :through => :keywordings
I want to find all posts t...
Does Rail's ActiveRecord have any special rules when attempting to set one of the column values in the model to nil?
The sanity check in the method freez always fails.
Model: Project
Column: non_project_costs_value (nullable decimal field)
def froz?
return !(non_project_costs_value.nil?)
end
def freez(val)
raise 'Already fr...
Hi,
I'm using prototype/rjs on rails 2.3.3 and ruby 1.86 and my form_remote_for to my "create" controller just displays the create.js.rjs instead of executing it. The strange this is that all the other action+rjs's work fine, just the "create" action isn't working Any help would be appreciated. Thanks in advance!
UPDATE: To clarify, it...
I am trying get acts_as_ferret working in my rails applications. I have installed the ferret gem. Installed the acts_as_ferret plugin.
This is what my model looks like now.
class User < ActiveRecord::Base
acts_as_ferret :fields => {
:first_name => {},
:last_name => {}
}
I have even tried
class User < ActiveRecord::Base
...
I wan't to make a string regexp safe in Ruby.
I have:
comment = "Just a comment someone makes"
Word.find(:all).each do |word|
comment.gsub!(%r{#{word}\s*}," ")
end
This replaces all words I've stored in the model Word with an empty space. The problem is if word contains for instance a left parenthesis "(" it will fail. Is there a...
I've been trying to get GeoKit installed on my computer and for the life of me I couldn't understand why acts as mappable was showing up as an unknown variable. I followed the instructions (I'm using Windows):
ruby script/plugin install git://github.com/andre/geokit-rails.git
I added to the environment.rb
config.gem "geokit"
and I...
I am using acl9 on top of authlogic on one of my projects. I like the approach acl9's approach but I guess I am trying to do something that is just not that simple (not to say impossible).
For reasons of usability I would like to have an inline admin panel. So for example say I got a resource auction and a nested resource auction/bid. W...