Hi there,
I'm trying to write an action generator for my Rails apps (probably the most basic form of metaprogramming you can get. My question is, how do I assign an instance variable that is available in views? To me, the code would look like this:
ApplicationController < ActionController::Base
def generate_custom_action
define_...
I am using ruby 1.8.7 and rails 2.3.4 . I am developing a plugin so I don't have too much of leeway.
In my controller I need to invoke a rake task. The rake task will take longer to finish so I am following the approach mentioned in Railscast which is
system "rake #{task} &"
This solution works great and everything is fine. I know th...
hi,
I have the following code
url = URI.parse("http://localhost:3100/tasks/#{id}.xml")
http = Net::HTTP.new(url.host, url.port)
# Make request
response = http.start do |http|
http.get(url.request_uri)
end
Whenever this code is run, it returns the following error
Net::HTTPHeaderSyntaxError in TasksController#show
wrong Content-...
My situation involves a directory containing MP3 files, and a database that should contain all the MP3 metadata (i.e. genres, artist names, album names, and track names) from the MP3 files in that directory. The database should always reflect what is in the directory, that is... the algorithm I'm searching for should never delete items f...
I have a Proposal model and a Signature model.
Proposal has many signatures and Signature belongs to proposal
My relationships work fine when I select a single Proposal, but when I do a Proposal.search and return multiple proposals, I can't access signatures.
I want to sort my proposals by signatures count, so I tried this:
Proposal....
Hi,
in some days I am giving a talk about a Rails project at university and I want to introduce the audience to Ruby.
I want to show them one or two really nice code examples to demonstrate how awesome Ruby is.
Do you know a good example?
Best regards
...
I'm using Maruku, to convert from Markdown (superset) to HTML, do you know how can I do to convert from HTML to Markdown?
...
Is there a python class equivalent to ruby's StringScanner class? I Could hack something together, but i don't want to reinvent the wheel if this already exists.
...
Low sleep so probably missing something trivial, but...
Based on various doc readings, I thought that this would generate a migration with table and column declarations included...
$ script/generate migration Question ordinal_label:string question_text:string
However, the result is...
class Question < ActiveRecord::Migration
def s...
Why is my irb history no longer saving?
...
I have a big 2-dimensional array A, and also a flat array B of two elements. How can I quickly access element from the A array using numbers (coordinates) in B? The only thing I can do now is:
A[B[0],B[1]]
But the path to these actual arrays through the names of members of my class is too long and dirty, and the actual array names are...
class A
#define class level attribute called key
class << self
attr_accessor :key
end
end
class B < A
end
B.key = "foo"
B.key # returns "foo"
A.key # returns nil
.
What is the approach if I want A.key to return "foo" in the above scenario?
...
I have a basic Ruby app that I am building with Sinatra, Datamapper and has user authentication using OAuth. When I receive the data back from the Oauth service, I save a record of a new user in an sqlite3 db.
What I don't know how to do is how to go about verifying the user record doesn't already exist on the user database table. I ca...
I'm looking for a library in PHP (or better yet in ruby) to handle an events calendar. I've looked a dozens of them and every one breaks down when it comes to recurring events. Many require and end date and most create every recurring event as a entry in a database or something.
Every suggestion I get is to use the Google calendar which...
I am new to rails so could use some help here. I have followed several tutorials to create a blog with comments and even some of the AJAX bells and whistles and I am stuck on something that I hope is easy. The default display for both blogs and comments is to list the oldest first. How do I reverse that to show the most recent entries an...
I have a a hash
foo = {'bar'=>'baz'}
I would like to call foo.bar #=> 'baz'
My motivation is rewriting an activerecord query into a raw sql query (using Model#find_by_sql). This returns a hash with the SELECT clause values as keys. However, my existing code relies on object.method dot notation. I'd like to do minimal code rewrite. Th...
I am new to rails so sorry for the simple question. I have followed several tutorials and set up a blog with comments (even using a little AJAX - Ha proud of myself). I have done some customizing and right now I am trying to display in the index.html.erb a comment count that is a clickable link that takes to you the show.html.erb page. H...
I am trying to create a form to allow users to change their password:
View:
- form_tag change_password_users_path do
= error_messages_for :user, :header_message => "Please Try Again", :message => "We had some problems updating your account"
%br
= label_tag :password, "New password:"
= password_field_tag "password"
%br
=...
I'm trying to extend ActiveRecord with the custom validation method validate_as_email so i could use it like this:
class User < ActiveRecord::Base
validates_as_email :email
end
I found description on how to extend ActiveRecord::Base class here: http://guides.rubyonrails.org/activerecord%5Fvalidations%5Fcallbacks.html
It says you hav...
Hello everybody,
I m trying to upload a file through attachment fu to amazon s3 storage using the following code :-
has_attachment :storage => :s3,
:content_type =>
['audio/mp3','audio/flac','audio/wav'],
:path_prefix => '#####',
:output_path => '######',
:processor =>...