You can compile a Java application and run it in any machine where the Java virtual machine is located, independently of the underlying hardware.
Since Ruby on Rails was built upon Ruby, I'm concerned if building software in Ruby in any environment is the same or not. There exists versions of Ruby for Windows, Linux and Mac at least.
...
Attempting to be DRY, I'm trying to assign to a model's instance variable after object initialization.
class WorkNote < ActiveRecord::Base
def after_initialize
self[:clockin]= WorkNote.last_clockout
end
def self.last_clockout
WorkNote.find(:first, :order => "clockout DESC").clockout
end
end
However, the method call i...
I'm developing an application where it seems likely that people will attempt to hide what their client IP address is behind a proxy server.
Is there a unified way to get what the actual client IP Address is behind the proxy? Looking at the Ruby docs, it explicitly states that
request.remote_ip
and
request.remote_addr
both would ...
I have a heredoc where I am using #{} to interpolate some other strings, but there is an instance where I also want to write the actual text #{some_ruby_stuff} in my heredoc, WITHOUT it being interpolated. Is there a way to escape the #{.
I've tried "\", but no luck. Although it escapes the #{}, it also includes the "\":
>> <<-END
#{R...
Hi, I need to display error message on model in rails,
my coding on model is like this,
if my_address.valid?
# I need here the validation error.
return nil
end
I used errors.add("Invalid address") but it is not working
please help to solve this problem ,
...
I am writing a rails application that sends emails when certain actions occur, users can then reply to these emails and the system needs to match the reply email to the original email sent to the user.
It seems like the best way to do this is to save the message id header field when sending messages, is this possible in ActionMailer? I ...
I want to set up a rake task to fill my CouchDB with fixtures data and have to get rid of the data in the database first. A good example for the whole procedure using MySQL can be found here. This examples contains the following part to delete the data of the model in the MySQL database:
# the list of models (pluralized) you want to imp...
In my Rails template, I'd like to accomplish final HTML to this effect using HAML:
I will first <a href="http://example.com">link somewhere</a>, then render this half of the sentence if a condition is met
The template that comes close:
I will first
= link_to 'link somewhere', 'http://example.com'
- if @condition
, then render th...
I am getting a mysterious 500 error when i try to deploy my first rails app on slicehost.
I have followed the Ubuntu Intrepid articles very closely and it seems to be all setup accordingly.
I am trying to run rails on Apache with Passenger. All I am trying to run here is a basic rails app with one scaffold (3 fields).
The apache err...
I want to expose some methods in control layer of one project to the control layer of another project according to web service. How can I realize this with REST? Or is there any other way to realize this in rails?
...
I have 3 different actions in a controller. Each takes different number of parameters.
In the application, all 3 are executed by the user clicking through links.
Now I need to have a form with a couple of fields where users can simply type what they are looking for. When users fill out the form, depending on what is provided one of the...
Suppose I have defined a bunch of named_scopes in a rails Person model. For example:
named_scope :male ...
named_scope :tall
named_scope :short
named_scope :happy
...whatever.
Well, what I'm doing is globbing a bunch of scopes in routes.rb and eventually I have an array of scopes...like this:
scopes = ["male", "happy", "short"]
Now...
What I'd like to do is join one model to another using two intermediary models in between..Here's the abstraction:
Country has_many Companies
Company has_many Buildings, Company belongs_to Country
Building has_many Rooms, Building belongs_to Company
Room belongs_to Building
I want to be able to do Country.first.rooms, so I thought th...
This might be a tough one
I have a site which is using a polymorphic comments model.
Lets say the first model is library, and the second is book
so we have, library/1/book/63/
how do I route it so comments are then library/1/book/63/comments/1 ?
Thanks,
Elliot
update: looking for code for routes.rb file
...
I have a sidebar that is going to have some logic in it, similar to how a view talks to a controller. Where do I put the logic in for the partial? Do I create a new controller for the layout and put it in there?
The layout is for logged in users, like a dashboard.
The dashboard is going to have a sidebar that shows the same dynamic cont...
I cannot seem to get a nested form to generate in a rails view for a belongs_to relationship using the new accepts_nested_attributes_for facility of Rails 2.3. I did check out many of the resources available and it looks like my code should be working, but fields_for explodes on me, and I suspect that it has something to do with how I ha...
When submitting a nested object form, I can't get it to reject invalid child objects because the reject_if proc doesn't see the Paperclip attribute.
Here are the relevant parts of my models & forms:
class Stage < ActiveRecord::Base
has_and_belongs_to_many :assets, :uniq => true
accepts_nested_attributes_for :assets, :reject_if => l...
I'm in the situation that I'm using sqlite with ActiveRecord and Rails (also, this is JRuby and so I'm actually using the jdbcsqlite adapter, in case that matters). Now, I'm trying to insert a row into the table attention_seekers, but only if there is no other existing similar row. Accordingly,
unless AttentionSeeker.find(:first, :con...
Take the following simple object model for example:
class Course
has_many :enrollments
has_many :students, :through => :enrollments, :after_add => :send_email
def send_email(student)
puts "Email Sent"
end
end
class Enrollment
belongs_to :course
belongs_to :student
end
class Student
has_many :enrollments
has_many :...
My current project I am pulling data from a remote database and saving it locally. During some stress test we are seeing horrible results with writing to a database. To give you some perspective:
Our stress test made ~9000 actions, which saves off about 54,000 records. (1 action = 6 records)
By 6 records, I mean 6 rows in 4 different t...