I've installed paperclip to my project as plugin using
ruby script/plugin install http://github.com/thoughtbot/paperclip.git
Model:
class Company < ActiveRecord::Base
has_attached_file :logo, :styles => { :large => "300x300>", :medium => "100x100>", :thumb => "50x50>" }
validates_attachment_content_type :logo, :content_type => im...
Hi, I'm calling a rails app from another using ActiveResource. I need to supply the id of the new object to the first app (yes, controller create in this app knows how to handle receiving an id), so I do something like this:
a = ActiveResourceModel.new(:id => 1231231, :name => "test")
a.save
However, instead of doing POST to create a ...
ActiveRecord use to call after_save callback each time save method is called even if the model was not changed and no insert/update query spawned.
This is the default behaviour actually. And that is ok in most cases.
But some of the after_save callbacks are sensitive to the thing that if the model was actually saved or not.
Is there a...
I was wondering if there is a nice pattern or better yet a specific function which applies a function until there is no longer a change in it's result.
url = "http://www.zzz.com/yyy/lt%255B1%255D.jpg"
unescaped = unescape(url)
while unescaped != url do
url = unescaped
unescaped = unescape(unescaped)
end
Although the code above is ...
I'm trying to click the Settings button on the home page, but when I do I get this page back:
#<WWW::Mechanize::Page
{url
#<URI::HTTP:0x1023c5fc0 URL:http://www.facebook.com/editaccount.php?ref=mb&drop>}
{meta}
{title nil}
{iframes}
{frames}
{links}
{forms}>
which is.. kinda empty! Is there some problems with these iframes ...
On Windows, how do I check to see if an authenticated user (ex: DOMAIN\User) is a member a local or domain group with Ruby?
In this case Ruby is running on Windows Enterprise Server 2003.
...
Hi folks,
I've the following code in a _form.html.haml partial, it's used for new and edit actions.
(fyi I use the Ryan Bates' plugin nested_form)
.fields
- f.fields_for :transportations do |builder|
= builder.collection_select :person_id, @people, :id, :name, {:multiple => true}
= builder.link_to_remove 'effacer'
...
A little background:
I've written a script that will act as a receiver for incoming Syslog/Email/Snmp(v1) traps. It receives the data and stores it as a custom defined object. My "messageSocket" is a means to control the behavior from a script outside of this general listener. I want to send messages to this to either start/stop on ...
I'm a bit confused as to how "relationships" are created/processed in ROR/rake.
Can anyone confirm if the following is correct?
Code the "insert xxx relation" in the DB Migration file. Migrate this once done.
Code in the final relationship (has_xxx...) in the model file.
If so, can ROR autogen the DB Migration file from changes in t...
This works, but it was a stab in the dark. I know little Ruby.
What's the accepted way to serve a plain old file for a given resource?
get '/xyz' do
File.read 'abc.html'
end
...
I want to learn Sed. Can you please point me to good references so that I can fully utilize it.
I want to learn it to perform more of the do-once-then-forget type administrative or dev-tools like tasks. So, I don't really care about performance or modularity or object orientedness etc when writing this type of code. Do you think it wou...
I can't work out from looking through the source what the difference is between the cattr_* and mattr_* methods provided in Class and Module respectively. I read this question: http://stackoverflow.com/questions/185573/what-is-mattr-accessor-in-a-rails-module which gives some details about both methods but doesn't highlight the differenc...
I'd like to make a website, it's not a huge project, but I'm a bit out of the web design loop. The last time I made a website was probably around 2002. I figure the web frameworks and tools have come a ways since then. It's mostly the design aspect that I'd like it to make easier. I can do the backend language in any language.
My qu...
I'm trying to make a method similar to attr_reader but I can't seem to get the instance of the class that the method gets called in.
class Module
def modifiable_reader(*symbols)
# Right here is where it returns Klass instead of #<Klass:0x1df25e0 @readable="this">
mod = self
variables = symbols.collect { |sym...
In IRB if I pass a string like "/domain/path" to Regexp.escape it just returns it the same. I thought that forward slashes are supposed to be escaped with a backslash? Am I missing something here?
...
Got
... '[]=': can't modify frozen string (TypeError)
when trying to modify what I thought was a copy of ARGV[0].
Same results for each of
arg = ARGV[ 0 ]
arg_cloned = ARGV[ 0 ].clone
arg_to_s = ARGV[ 0 ].to_s
arg[ 'x' ] = 'y'
arg_cloned[ 'x' ] = 'y'
arg_to_s[ 'x' ] = 'y'
...
Hi,
I want my rails app to accept dates for a date field in the format dd/mm/yyyy.
In my model I have tried to convert the date to the American standard which I think the Date.parse method that Rails will call on it is expecting:
before_validation :check_due_at_format
def check_due_at_format
self.due_at = Date.strptime(self....
I have a model, let's say Attachments, that uses attachment_fu to accept file uploads from the user. I want to "deep copy" (or in Ruby-ese, deep clone) an Attachment, thus creating a completely new binary object in the "db_files" table.
I've found that it is not quite a solved problem yet. This blog posting:
http://www.williambharding.c...
In Ruby 1.8.7 I can do the following in order to get the subject of a binding object:
binding.eval("self")
However, in Ruby 1.8.6, the eval method is private, so I expose it like this:
class Binding
public :eval
end
Which seems to work fine, however, binding.eval("self") returns the binding itself, not the subject of binding.
Ho...
I'm using Ruby+Watir to request pages through Firefox.
I would like to record the headers and content of every http request made through the browser.
Would it be possible to configure a proxy solution to store this information, either in a file or pipe it straight into an application? Could I use something such as squid or nginx to rec...