ruby-on-rails

Rails will_paginate routing caching duplicate pages

I use the will_paginate plug-in. In oder to generate routes that I can cache ( /posts/index/2 instead of /posts?page=2) I added the following to my routes.rb: map.connect '/posts/index/1', :controller => 'redirect', :url => '/posts/' map.connect 'posts/index/:page', :controller => 'posts', :action => 'index', ...

Help with rails and tinyMce

I have been using tinyMce_hammer plugin to use tinymce in my rails app... but right now I also want a way for my users to upload photos and insert them into their wysiwyg editor.... is there a simple way to get this done??.. is there any other wysiwyg editor that works with rails and comes with this feature built in??... what do you recc...

How do I route user profile URLs to skip the controller?

Right now my user profile URLs are like so: http://example.com/users/joeschmoe And that points to the show method in the user controller. What I'd ideally like to do is offer user profile URLs like this: http://example.com/joeschmoe So, what sort of route and controller magic needs to happen to pull that off? ...

Where should I place my own "module" within rails application?

Some functionality within my rails application looks better as if it was a separate "module", that should be accessed via require. For example, assume it's a function to calculate Fibonacci numbers. The functionality is independent on rails application and can be reused in other projects, so it should not be stored near application co...

RoR: partials with resources

I have a problem, trying to render partials in ruby on rails with the short notation for resoures. Somehow, RoR displays simply nothing that has to do with the partial, but i get no errors as well. I mean, the resulting HTML looks like the call for the partial simply wouldn't be there. I'm also confused, because i can see in the log, tha...

How to use Rails I18n.t to translate an ActiveRecord attribute?

Trying to use my active record translations in config/locales/de.yml also in my views. I thought I am clever using this: de: activerecord: attributes: user: login: "Benutzerkennung" comment: "Bemerkungen" And in my view this: <%= label_tag :login, t('activerecord.attributes.user.login') %> But instead o...

Importing old data with Rails and Paperclip

I'm using paperclip for attachments in my application. I'm writing an import script for a bunch of old data, but I don't know how to create paperclip objects from files on disk. My first guess is to create mock CGI multipart objects, but that seems like a bit of a crude solution, and my initial attempt failed, I think because I didn't ge...

How to use the authorizable_type and authorizable_id field in role table of the rails-authorization-plugin?

I know these fields are for polymorphic associations, but I'm not sure how to use them, Is there any example or some help about this? ...

Have Capistrano Insert Password From Prompt Into Environment.rb File

I am using Action Mailer and have my configuration settings for Action Mailer in my environment.rb file. I would like to post my project in a public repository along with an environment.rb file, but I do not want to include my mail server's login information. How does one configure Capistrano's deploy.rb so that it prompts the user for t...

Rails - Roles or Inheritance?

I began writing an app using declarative_authorization (http://github.com/stffn/declarative%5Fauthorization) but I'm now wondering if it's the correct approach. In my app, I was giving some Users a "customer" role, some an "administrator" role, and some a "superadmin" role. That was working fine, but I now realise that I need some field...

Automatically fill in form fields in Rails?

Lets say you had a simple form to create a new article object in your application. <% form_for @article do |f| %> <p> name:<br /> <%= f.text_field :name %> </p> <p> link:<br /> <%= f.text_field :link %> </p> <p> <%= submit_tag %> </p> I'm using the RSS feed parser Feedtools to get the article names but I can't seem to auto...

Getting user information using either user.login or user.id

So I have a url like the following localhost/users/:id/posts which gives the posts of that particular user. Now this id can be either his login (which is a string) or the id (user.id) which is technically an Integer but params[:id] is always a string. So how do I implement this an action. @user = params[:id].is_a?(String) ? User.find...

Variable symbol in Params object in rails

Hi all I have the following code: @profile.update_attributes(params[:xxxx_profile]) where xxxx stands for either male or female. Basically the form submit passes either a set of female_profile[foo] or a male_profile[foo] and i want to change it accordingly. Assuming I have a string that can be inserted in lieu of xxxx, how do I dyn...

Ruby on Rails: Length of Video as a Paperclip Attachment

I created a rails class with a video attachment, and i want to know how to get the length of a video that is uploaded to my application. How can I achieve that ? ...

Ruby on Rails: How do I detect a specific mongrel instance in a cluster during startup?

We run an application with a half dozen mongrels. A new feature that we've added is a scheduler (rufus-scheduler) that runs within a mongrel and provides cron-like background task processing. We want ot run this scheduler on only one of our mongrels but we can't figure out how -- during startup (environment.rb) -- to identify the speci...

Rails helper functions

Where can I find a complete list of Rails helper functions (such as form_for)? ...

Puzzled by ror Mechanize

I'm trying to use mechanize to perform a simple search on my college's class schedule db. The following code returns nil, however it works logging into facebook and searching google (with diff url/params). What am I doing wrong? I'm following the latest (great) railscast here. Mechanize documentation has been useful but I'm still puzzle...

rails page won't display entirely

I'm having the most peculiar problem, and I was hoping I someone could point me in the right direction on how to address it (or even locate it...). I'm working on a rails site, and the pages display in most browsers without any issues. In others (AOL, IE 6 - 7, and some of the other lesser used ones) the page will load, with all of the...

Install Gem Locally

First let me say I cannot do gem install, I don't know why. Probably because I live in China and the firewall random things. So I have to locally install gems. For example, i want to install this gem riddle. But this gem downloads as a tar or zip and when i open it it is a folder not a .gem file. So what to do? ...

Can I Change Look / Feel Of Scaffolded Pages With Mostly CSS?

I am using a web framework (Grails, similar to Rails) that has abilities to auto-generate a lot of code through scaffolding. As a result, all of my CRUD pages are currently automatically generated, and I even have ability to inject additional HTML code whenever I want to to further customize the content of those pages. I can control t...