Hello, I was wondering if it was possible to use the find method to order the results based on a class's has_many relationship with another class. e.g.
# has the columns id, name
class Dog < ActiveRecord::Base
has_many :dog_tags
end
# has the columns id, color, dog_id
class DogTags < ActiveRecord::Base
belongs_to :dog
end
and I w...
I'm following Railscast 88 to create a dynamic dependent dropdown menu. http://railscasts.com/episodes/88-dynamic-select-menus
I'm rendering these dropdowns inside a partial that I'm using in a multi-model form. The form I'm using follows the Advanced Rails Recipes process by Ryan Bates. Because I'm rendering the dropdown inside a ...
I'm trying out OAuth for twitter api authentication and ran into a brick wall when my code spits out the message:
(instance of OAuth::Consumer needs to have method `marshal_load')
My code:
@consumer=OAuth::Consumer.new( "token","secret", {
:site=>"http://mysite.com/"
})
@[email protected]_request_token
session[:reque...
I want to conditionally switch on/off certain functionality in my Rails app, for example in my current app I have the following functionality "product show case", "product search", "ecommerce", "user management" etc
If I implement the same app for someone else they probably might not want the ecommerce function, how do I disable the eco...
I have an existing Project record, and I'm importing a CSV file to update the associated Project attributes. However, often the CSV will contain blank fields and I don't want to overright exisiting attributes if the related CSV field is blank.
Something like this:
project.update_attributes(:name => row.field('project_name') unless row...
I am extending a class (which is in a plugin) by including a module, this is done in an initializer.
require 'qwerty/core/user'
User.send :include, Qwerty::Core::Extensions::User
However in development before every request (and after reload! is called in the console) all models are reloaded but because the initializers are not run ag...
Hey,
i thought about using observers or callbacks.
What and when you should use an observer?
F.e. you could do following:
# User-model
class User << AR
after_create :send_greeting!
def send_greeting!
UserNotifier.deliver_greeting_message(self)
end
end
#observer
class UserNotifier << AR
def greeting_message(user)
...
...
<%=yield%> works perfectly if my template is called layouts/application.erb. However, if I change the template to something else, then the yield doesn't work. For instance, my controller method is
render :template=>'layouts/survey'
and the right template gets rendered, but its yield method doesn't show the output of the current action...
Hi,
I have a rails application in which I implemented some feature. Now I want to remove that feature without breaking the code. Since the application is running on the production server, this makes it a little bit critical. How do I do the following.
remove all the tables from the database concerned with this functionality?
remove th...
I need to use an existing PostGIS database from my Rails application. So far I am able to access the DB just fine, GeoRuby nicely converts the 'geom' column into a Point object.
What I am looking for is an easy way to execute ActiveRecord-like queries on those tables, e.g.
Poi.find_within_radius(...)
or similar spatial queries like d...
In /initializers/time_formats.rb I have this:
Time::DATE_FORMATS[:profile] = "%m / %d / %Y"
However this obviously produces dates such as: 09 / 08 / 2001
Google tells me my best bet is to use some kind of gsub regular expression to edit out the 0's. Is this true or is there a better alternative?
...
I've always thought this sort of thing ugly:
require File.join(File.dirname(__FILE__), 'hirb/config')
Is there a prettier alternative, maybe one written for Rails?
require_relative 'hirb/config'
require_relative '../another/file'
...
I'm trying to create a form validation.
I added @user.errors.add_to_base "TEST" to my controller, and if I call @user.valid?, it returns false (yes, this is correct). But the error "TEST" isn't displayed (errors from the model, like from validates_presence_of, are).
Why does it 'delete' my error? How can I avoid it?
...
Hey,
I'm getting the following error in my development.log
[paperclip] An error was received while processing: #<Paperclip::NotIdentifiedByImageMagickError: /tmp/stream28514-0 is not recognized by the 'identify' command.>
And i've googled about this error and i found out that many people have solved this by adding this line
Pa...
I have a form that will not submit:
<% form_for :venue, :html => { :id => "create_venue_form" } do |f| %>
<%= render :partial => 'venues/venue_form_fields', :locals => { :f => f } %>
<%= submit_to_remote 'add_venue_button',
'Save Venue',
{
:url => add_venue_path(@user.id),
...
Say I have Course that has_many Students. I also have def top_student in the Course class. I now have an active_scaffold on top of Course, but if I add top_student as a column it show shows #, but no link. I'd like a link to the Student who is the Top Student. Any way to make this happen?
...
How can I remove the div from authenticity_token in Ruby on Rails?
Thanks.
...
Hi,
Considering this:
@article = Article.first(:joins => :category)
Does ActiveRecord provides a generique method which return a array of any belongs to class name?
For example:
@article.name.parents # => ["category"]
Thanks
...
Currently, I have a 6-model ruby on rails application, that I added authlogic to.
The overall setup is
User :has_many categories, topics,messages
Categories has_many topics,
Topics has_many messages
(With and the corresponding opposite belongs_to links).
When I try to access current_user.categories.find(2), no results are returned i...
I seem to be having some extremely odd cache_money interactions.
When I am on the console, and I create a new instance of a class and save it I see the cache misses and cache stores on my memcached console output. Then when the create finishes I see a bunch of cache deletions.
If I then try to do any kind of find for the newly created...