ruby-on-rails

Using fixtures with factory_girl

When building the following factory: Factory.define :user do |f| f.sequence(:name) { |n| "foo#{n}" } f.resume_type_id { ResumeType.first.id } end ResumeType.first returns nil and I get an error. ResumeType records are loaded via fixtures. I checked using the console and the entries are there, the table is not empty. I've found ...

How to change validation messages on forms

Hi, the website I'm developing will be in spanish. Therefore, I'll need the error messages in that language. I created a file under Configuration directory called 'en.yml' in order to accomplish this. And I added the following code in it: es: activerecord: errors: models: announcement: attributes: ...

vestal_versions and htmldiff question of reversion...

I'm guessing there's probably an easier way to do what I'm doing so that the code is less unwieldy. I had trouble understanding how to use the revert_to method... i wanted something where i could call up two different versions at the same time, but this doesn't seem to be the way that vestal_versions works. This code works, but I'm won...

Creating content for rails-based applications

Hi, I'm facing a problem of cleaning up my application in Ruby on Rails. What I have is a pretty standard 3-panel, header and footer layout where different parts of the screen contain different functionality. By that I mean for example that the header contains (among others) a select that allows one to select parts of the application a...

bidirectional habtm linking

Hi, all. I have application with 2 groups of models - content based (news, questions) and "something" based (devices, applications etc). I need to link all models between groups - for example question may belongs to 3 different things - one application and 2 devices. The same - for news. From other side - i need to see all news articles ...

Passenger problem: "no such file to load" -- /config/environment

I've been researching this one and found references to similar problems here and there, but none of them has led to a solution yet. I've installed passenger (2.2.11) and nginx (0.7.64) and when I start things up and hit a Rails URL, I get an error page informing me of a load error: no such file to load -- /path/to/app/config/environment...

Include dynamic info in Rails emails

Hi Everyone, I have managed to get my email problem sorted so now everytime a case is created an email goes out to the specified address. I have a usermailer.rb def makeakase(email, name, jobno, casesubject) recipients email from "no-reply@your_rails_app.com" subject "FW: Kase creation from Survey Manager" sen...

Rails scalar query

I need to display a UI element (e.g. a star or checkmark) for employees that are 'favorites' of the current user (another employee). The Employee model has the following relationship defined to support this: has_and_belongs_to_many :favorites, :class_name => "Employee", :join_table => "favorites", :association_foreign_key => "fav...

Prawn PDF with Rails mailer?

Hi Everyone, I have successfully created an email that sends on creation of a Kase, but now I need to attach a PDF that is created on the fly by Prawn and Prawno. Basically when you visit a kase such as application.com/kase/1 you just append the URL with .pdf i.e. application.com/kase/1. I spent ages getting the PDF to work and look h...

Rails ActiveResource Associations

I have some ARes models (see below) that I'm trying to use associations with (which seems to be wholly undocumented and maybe not possible but I thought I'd give it a try) So on my service side, my ActiveRecord object will render something like render :xml => @group.to_xml(:include => :customers) (see generated xml below) The models...

Ruby on Rails Truncate text - can I use it for a combination of title and content?

I have <%=link_to topic.title, topic_path(topic) %> - <%= truncate(topic.description_without_embed, :length=>50, :omission =>"...") %> But what I really want to do is to truncate both the title and the post to 50 characters. How can this be done? The output should look something like Lorem ipsum dolor sit amet, consectetur adipisci...

Putting data from local SQL database to remote SQL database without remote SQL access enabled (PHP)

Hi, I have a local database, and all the tables are defined. Eventually I need to publish my data remotely, which I can do easily with PHPmyadmin. Problem however is that my remote host doesn't allow remote SQL connections at all, so writing a script that does a mysqldump and run it through a client (which would've been ideal) won't hel...

Rails parse url to hash(Routes)

Hello. How can I parse url string to hash like {:controller => 'controller_name', :action => 'action_name', :id => 'id'} ? ...

undefined method `parameterize' for nil:NilClass

I've been trying to do SEO friendly urls, and managed to get it work, but when I call index action on blogs, I get a weird "undefined method `parameterize' for nil:NilClass." The method works when using show method. #model def to_s title end def to_param "#{id}-#{to_s.parameterize}" end #controller @blogs = Blog....

Ruby on rails multiple apps hosting (name server)- configuration question

I am looking to host multiple ruby on rails apps and want to use lighttpd or nginx.How do I do multiple name server configuration. ? I know how to do it in apache through webmin control panel.But trying to move away from apache here ...

Mootools in Rails

For my client side development I use MooTools primarily, I have also just recently started learning rails. What is the best method of using Mootools in rails pages? Just adding my code inline like I would any other server side language? Or is there a better and cleaner way to do things? Basically I'm asking the most conventional way of ...

Export Excel in ruby on rails

Hey guys! I want to export the page Info to Excel ,who can tell me how can i do this? thank you! ...

Rails user authorization

I am currently building a Rails app, and trying to figure out the best way to authenticate that a user owns whatever data object they are trying to edit. I already have an authentication system in place (restful-authentication), and I'm using a simple before_filter to make sure a user is logged in before they can reach certain areas of ...

[Ruby on Rails] Data Structure

I am building a online form, with about 20 multiple choice checkboxes. I can get the nested data with this command. raise params.to_yaml I need to store these data and call them again later. I want to sort out which user chose which specific checkbox, i.e. who chose checkbox no.2? What's the best way to store these data in database...

Rails: How to perform callbacks on a model that is not updated but is related to updated model

to KIS I have two models: Reservations and Containers. Container has_many :reservations Reservation belongs_to :container When I update a reservation I also want to perform call backs on the respective Container. What is a good way to do this? Should I be using nested rest routes, put the container logic in the Reservation mod...