I have the following models set up:
class Contact < ActiveRecord::Base
belongs_to :band
belongs_to :mode
validates_presence_of :call, :mode
validates_associated :mode, :band
validates_presence_of :band, :if => :no_freq?
validates_presence_of :freq, :if => :no_band?
protected
def no_freq?
freq.nil?
end
def no_ba...
// using Rails 2.3.5
//routes.rb
map.resources :users,
>> user = User.first
>> helper.link_to user.name, user
I am getting nil error. I thought the above code should work. What am I missing?
...
What I'd like to be able to do is:
in config/routes.rb
resources :posts
in config/locale/en.yml
en:
resources:
posts: "posts"
new: "new"
edit: "edit"
in config/locale/tr.yml
tr:
resources:
posts: "yazilar"
new: "yeni"
edit: "duzenle"
and get
I18n.locale = :en
edit_post_path(3) #=> /posts/3/edit
I18...
I have an object of type Hash that I want to loop over via hash.each do |key, value|. I would like to get the number of times I've been through the loop starting at 1.
Is there a method similar to each that provides this (while still providing the hash key/value data), or do I need to create another counter variable to increment within...
I have set PassengerPoolIdleTime to 0, with the expectation that this means I can "warm" up a bunch of passenger processes on my server, and the next time I have a burst of traffic (even if it is days later), they will all be warmed up and ready to accept requests.
What I'm seeing instead is that every morning when I get up, passenger-s...
Hey all. I've got a new app up and running on a new ubuntu server. It's working fine generally but i can't get ar_sendmail working. I'm following the instructions on this page:
http://www.ameravant.com/posts/sending-tons-of-emails-in-ruby-on-rails-with-ar_mailer
The setup is all done, ie i can "deliver mails" which just saves records...
I've got a text area on a web site that should be limited in length.
I'm allowing users to enter 255 characters, and am enforcing that limit with a Rails validation:
validates_length_of :body, :maximum => 255
At the same time, I added a javascript char counter like you see on Twitter, to give feedback to the user on how many characte...
I'm building a website with user generated content. On the home page I want to show a list of all created items, and I want to be able to sort them by a view counter. That's sound easy, but I want multiple counters. I want to know which was the most visited item in the last day, last week or last months or overall.
My first Idea was to ...
I want to store a path for a special directory used by my Rails application. Should I store that in environment.rb, or is there another place this is meant to go?
THE_DIRECTORY_PATH = '/path/to/directory'
Let's assume my controllers + models or libraries in /lib need access as well.
...
Hey. How can I create a log where part of a string is colorized (aaa)?
Rails.logger.info "Color1: aaa Default bbbbbbb"
Thx.
...
I am looking to reproduce the following with Formtastic:
<% form_tag '/search', :method => 'get' do %>
<%= text_field_tag :q, params[:q] %>
<% end %>
So far I have:
<% semantic_form_for :search, :html => { :method => :get } do |form| %>
<% form.inputs do %>
<%= form.input :q %>
<% end %>
<% end %>
However, this requires a...
I want to log into https://www.t-mobile.com/ programmatically. My first idea was to use Mechanize to submit the login form:
However, it turns out that this isn't even a real form. Instead, when you click "Log in" some javascript grabs the values of the fields, creates a new form dynamically, and submits it.
"Log in" button HTML:
<bu...
Setup:
ModelA <- habtm -> ModelB <- has_many / belongs_to -> ModelC
I'd like to setup a habtm between ModelB and ModelC, I've tried
has_many :ModelA, :through => :Model3
But that doesn't seem to work. Is there a way to accomplish this?
...
I followed all of the instructions so far from:
http://code.google.com/p/appengine-jruby/wiki/RunningRails and
http://gist.github.com/268192
Currently, I'm just trying to get to hello world. I'm getting these
errors when I just run the dev_appserver.rb
238:hello-world jwang392$ dev_appserver.rb .
=> Booting DevAppServer
=> Pres...
Hello,
on my web site I want to have login/registration form in modal window done using facebox (jQuery plugin). What is better:
Create view with one method and template that has form and refer facebox to this view.
Create static HTML file in public directory and refer facebox to this static page.
What I want to achieve is:
Easy v...
So I came about the strangest rails bug. I have been starting a new rails3 app, and just installed will_paginate 3.0pre. Unfortunately the rails 3.0.0.beta2 update made some of will_paginate 3.0pre code deprecated. I did a quick fix.
In gems/will_paginate-3.0.pre/lib/will_paginate/railtie.rb:
...
#railtie_name :will_paginate #Old co...
I'm trying to understand the best options for pulling off a wizard form in ruby on rails. Ideally I'd like to have it so the application signup has a back and next button that allows the user to submit data in steps.
So in step 1 they could fill out contact info. Once they are done they could click next and be on step 2 to fill out paym...
Hello,
I'm trying to perform a daily operation on a larger than normal dataset (2m+ records). However, Rails seems to take a very long time performing operations on such a dataset. Operations like
Dataset.all.each do |data|
...
end
take a very long time to complete (I assume this is because it can't fit all the items into memory a...
Hi,
I have problem with my code
class Post < ActiveRecord::Base
end
class NewsArticle < Post
has_many :comments, :as => :commentable, :dependent => :destroy, :order => 'created_at'
end
class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic => true, :counter_cache => true
end
And on attempt go get comments for s...
Hey,
I stumbled upon a problem of how to make work together acts_as_taggable (on steroids) and will_paginate gems. What I found on this problem is this: http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/
But it's dated of 2007, may be there's something more recent? A...