ruby-on-rails

ActiveRecord Migration & Rake tasks not loading models?

I know that you can do something like this to load the rails environment: task :my_task => :environment do MyModel.find(1) end But it seems the code in the models are not executed. I am using acts_as_audited, and there is a nice class function which retrieves all models which are being audited. The call looks something like: ...

how to take ActiveRecord associations to the DB

I execute the following commands to make the model: script/generate model user firstname:string lastname:string script/generate song group songname:string songtitle:string a user has_many :songs and a song belongs_to :user after this I run rake db:migrate however, the associations are not carried to my actual DB. Because in my actu...

How can I test different environments (e.g. development|test|production) in Cucumber?

Take this scenario. I have a Google Analytics tracking code, and I only want it to show up in Production mode. So I might have two scenarios like this: Scenario: Don't embed tracking code in development or test mode Given the app is not in production mode When I go home Then I should really not see the tracking code Scenario: Emb...

File creation in rails + jquery

I am new to Rails. In my web application, the user can type the contents of a file in a textarea or a content Editable iFrame and when he saves the file, the contents should be written to the file with the file extension specified by the user. How can I do so?? ...

RoR-ajax-reload partial file

hi I am using checkboxes, on clicking checkbox my partial page has to refresh. And partial page is displayed in thickbox. I want to refresh it using ajax. I am using code written below, but no page reload is happening respond_to do |format| format.js{ render :update do |page| page.replace_html :content, :partia...

Rails Index.html.erb misbehaving

I thought I was following this RoR tutorial to a T, but apparently not. They instructed that we write this code into apps/views/index.html.erb <h1>Listing posts</h1> <table> <tr> <th>Name </th> <th>Title </th> <th>Content </th> </tr> <% for post in @posts %> <tr> <td><%=h post.name %...

What is current_ability in cancan's accessible_by (fetching records)?

In the documentation of cancan it shows how to fetch all accessible records (in http://wiki.github.com/ryanb/cancan/fetching-records) in this way: @articles = Article.accessible_by(current_ability) but what is current_ability? I've tried passing the current user which I'm using for authentication and authorization, but I've got this e...

Ruby on Rails, how to structure this HAML code to not include some <div> at top level?

if the HAML is: .class1 .class2 .class3 %div content... many lines How can it be made so that it doesn't respond with class1 and class2 if it is Ajax? - if !request.xhr? .class1 .class2 .class3 %div content... many lines won't work, because if not Ajax, then class3 is not a child of class2. It mi...

How to organize actions that don't fit into the normal MVC

I am creating a survey application so I created a surveys controller that behaves very restfully creating, updating, etc a Survey. However now I'm adding other actions to it like 'take', for taking a survey, and 'share', for sharing a survey. There are more actions too. I'm starting to wonder if I should organize my code differently a...

Ruby on Rails + Sybase + Ubuntu Linux - Error: Could not load SQLAnywhere DBCAPI library

I'm actually brand new to Ruby and Sybase both, but here goes: I'm trying to connect Ruby up to a remote Sybase server. (I've been successful with a local MySQL server.) I've done: gem install sqlanywhere gem install activerecord-sqlanywhere-adapter (and set up the stuff in the database.yml, of course) Still, when I got to http://...

Multiple App Support Using APN on Rails Gem

Hello, I have a couple iPhone apps talking to one ruby on rails server. I have been using the apn_on_rails gem by mark bates/PRX (http://github.com/PRX/apn_on_rails) to offer push notifications to both apps. The README specifies how to support one app, but I need to support two apps. Not only that, but I would like to send out these not...

Query to find topics depending on the tag

Hi All, I want a search functionality in my application for the data like following topic_id tag 1 cricket 1 football 2 football 2 basketball 3 cricket 3 basketball 4 chess 4 basketball Now when i search for term cricket AND football o/p should be topic_id ...

Including helpers when rendering a template/partial by hand

I use the following code to render a template to a string that I can use later on: renderer = ActionView::Base.new(MyApp::Application.config.view_path) # INCLUDE HELPERS HERE data = renderer.render(:partial => template, :locals => locals) However, I want to be able to access some helpers (actually all). In rails 2.3 I was able to do t...

Joins Tables & Rails

I have events and users/teams. class Event has_many :users, :through => :registrations end class User has_many :events, :through => :registrations end class Registration belongs_to :users belongs_to :events end When I register a user, I'm connecting them to the event like so: @event.users << @user Does this implicitly creat...

Ruby on Rails: is it okay to use old school database access without migrations?

I'm switching to RoR from ASP.NET MVC. Yeah, migrations are cool, but I do not need to use different databases in my web applications. Postgresql will do just fine. So is it okay if I use PGAdmin to create and administer my databases and schema and avoid all these fancy migrate, rake etc? Update Thanks everyone! Now I better understa...

rails 2.3 config.load_paths in development mode

I moved some files into subfolders within my app/models directory and added those directories in the config.load_paths in config/environment.rb: config.load_paths += Dir["#{Rails.root}/app/models/extras"] within app/models/extras I've got a few ActiveRecord models, for instance say: app/models/extras/blog_post.rb class BlogPost < Ac...

Sunspot highlights not appearing

I've gone through the docs in github: http://github.com/outoftime/sunspot to find solutions for highlighting, but it doesn't seem to work for me. My Job model has something like this block (omitted some fields on purpose): searchable do text :name string :name, :stored => true time :updated_at time :created_at t...

Rails and association in to_json

I have an association one to many from foo and bar. i do a foo.to_json(:include => :bar) but i want to display not all the rows of bar, but only the last, how to do? ...

Decision maker question: compare ASP.NET / Ruby / Python on web UI controls

I need to learn a language for writing web applications (not websites!). After some research in google and stackoverflow I ended up that the choice should fall in: 1) Ruby + Rails 2) Python + Django 3) c# + ASP.NET For sure even pickng one randomly would not be a bad choice, but my question here is specific to UI controls. I come fr...

Render controller action from another controller

I think the code is more explicit option A class RedirectController < ApplicationController def index redirect_to :controller => 'posts', :action => 'show', :id => 1 # it works end end option B class RedirectController < ApplicationController def index render :controller => 'posts', :action => 'show', :id => 1 ...