ruby-on-rails

How to create an "edit" url for a restful resouce?

In my partial template, there is a varible named "resource", it may be a question or an answer. I want to build a link to edit it, but when I use it, I don't know what it is, so I can't write: <%=link_to 'edit', edit_question_url(resource)%> or <%=link_to 'edit', edit_answer_url(resource)%> I wonder if there is such a method, say...

in Rails3 beta 4 where is the code that gets executed when you type 'rails server'?

I'm tracing my way through the source code and can't seem to find where the command "rails server" would be for a generated app. Where is it? Also is there some way I can track down these things in the future? ...

Use Rails 3's ActiveSupport core extensions outside rails

Hi guys. I'm having a problem using ActiveSupport's core extensions on a gem I am developing. I had it working with AS 2.3.8, but as soon as I wanted to port it to 3b4, the extensions stopped working and my test results are filled with lines such as: undefined method `blank?' for "something":String I've included it via gem "activesu...

How do I create spaces between every four integers in Ruby?

I am trying to take the following number: 423523420987 And convert it to this: 4235 2342 0987 It doesn't necessarily have to be an integer either. In fact, I would prefer it to be a string. ...

Ruby on Rails: How to run a rake task for the env.rb?

in features/support/env.rb in cucumber, i would like to have a rake task run everytime i start my tests... but not before each scenario.. just.. once. This is what i need to run Rake::Task["db:test:prepare"].reenable Rake::Task["db:test:prepare"].invoke ...

Drop down with predefined values

How will i add predefined values to a collection_select? Like... US UK AUS PAK ...

:wrapper_tag, :wrapper_class options (and more) with simple_form and Rails 2.3 ?

Hi, I'm making my first Rails project and I'm using the simple_form gem (version 1.0) with a Rails app (version 2.3.5). simple_form repository v=1.0 Is there any way to implement the nice options :wrapper_tag, :wrapper_class, :wrapper_error_class ? Or maybe I'm missing something? :-D Thank you for your advices Fro_oo ps : I can't ch...

Joining the same model twice in a clean way, and making the code reusable

I have a model Painting which has a Paintingtitle in each language and a Paintingdescription in each language: class Painting < ActiveRecord::Base has_many :paintingtitles, :dependent => :destroy has_many :paintingdescriptions, :dependent => :destroy end class Paintingtitle < ActiveRecord::Base belongs_to :painting belongs_to...

File read fails when using Delayed Job

How to check that my params['Filedata'] is corrupted or not? I have function it's reading file from params['Filedata'] and writing it to the other file. File.open(upload_file, "wb") { |f| f.write(params['Filedata'].read) } this line working fine for me.. But when i am calling this function with delayed job function send_later than I...

Rails "Missing these required gems" error for installed gems

I know this has been asked multiple times before, but I've tried those things and still am not having any luck. For the mechanize gem, I keep getting the "Missing these required gems" error when I run db:migrate on my production server. Here's the full error: Missing these required gems: mechanize You're running: ruby 1.8.6.111...

Apache serving wrong Content-Type for Rails files

Apache keeps serving up my Rails files with a Content-Type of 'text/plain' in the header. I have mod_mime installed, a mime.types files with all the correct MIME assignments, and the following code in my configuration. Any thoughts? DefaultType text/plain <IfModule mime_module> TypesConfig /etc/apache2/mime.types AddType applic...

Problem building relationships between models

Until now, I've been using acts_as_taggable_on plugin for tagging announcements. That plugin creates the following tables: taggings: relates tags and announcements table(for the tagged item, it has a field called taggable_id, which I rename to "announcement_id" for what I'll explain below). tags: has the tag ids and names. The other...

Saving form values to database after a user logs in

Hi. We have a form with ratings to submit for a certain restaurant. After the user has entered some values and wants to submit them, we check whether the user is logged in or not. If not, we display a login form and let the user put in his account data and redirect him to the restaurant he wanted to submit a rating for. The problem is, ...

Rails: Custom template for email "deliver_" method?

I'm building an email system that stores my different emails in the database and calls the appropriate "deliver_" method via method_missing (since I can't explicitly declare methods since they're user-generated). My problem is that my rails app still tries to render the template for whatever the generated email is, though those template...

Inheritance in Ruby on Rails: setting the base class type

I am implementing a single table inheritance inside Rails. Here is the corresponding migration: class CreateA < ActiveRecord::Migration def self.up create_table :a do |t| t.string :type end end Class B inherits from A: class B < A end Now, it's easy to get all instances of class B: B.find(:all) or A.find_all_by_t...

Ruby on Rails and Domain Driven Development

Hi guys, As I know ruby on rails are using Active Record with table per class strategy. I wonder if it possible to use Rails in domain driven design style, which require ORM which has more level of abstraction of data model, such as NHibernate. Best regards, Alexey Zakharov ...

Updating cached counts in MySQL

In order to fix a bug, I have to iterate over all the rows in a table, updating a cached count of children to what its real value should be. The structure of the things in the table form a tree. In rails, the following does what I want: Thing.all.each do |th| Thing.connection.update( " UPDATE #{Thing.quoted_table_name} ...

problem with ruby script/delayed_job start. delayed_job and daemon on windows.

gettting this error. pid-file for killed process 8600 found (C:/cyncabc/tmp/pids/delayed_job.pid), deleting. c:/ruby/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/daemonize.rb:103:in `fork': fork() function is unimplemented on this machine (NotImplementedError) from c:/ruby/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/da...

Establishing connection w/ Amazon s3 from Heroku

I am attempting to deploy my first app on Heroku and having a little trouble getting the S3 connection to work. Here is the error I am getting from the Heroku logs: AWS::S3::CurrentBucketNotSpecified (No bucket name can be inferred from your current connection's address (`s3.amazonaws.com')): I have the following configured: config...

Expanding a row in a div-based table

I have a stack of <div> elements that show a name. I'd like to include a + link off to the side of each <div> that, when clicked, expands the <div> and adds more detailed information (from a RoR controller). After poking around on the net, I found link_to_remote and related RoR stuff, but I can't seem to get the right combination to wor...