ruby-on-rails

before_filter and respond_to formats

In a controller in my Rails app, I can do this: before_filter :login_required, :except => :index But I would like to apply the filter not only based on the action name but on the format of the request. In other words, I would like to do something like this: before_filter :login_required, :except => {:action => :index, :format => :js}...

Mysql Dropping Connection

I am on Instant Ruby on Rails Mysql version 5.0.27, developing a system and all was going ok (sort of). Now the database keeps dropping. I found some comments that the userid needs to be root and password blank, I had changed the password, so I changed it back. Views run fine displaying and making changes than 500 Internal error, log say...

uninitialized constant ActionController::Dispatcher::MiddlewareStack

I installed some new gems for testing and ran into an uninitialized constant ActionController::Dispatcher::MiddlewareStack error. I followed the instructions on the gem rdocs-specified the gem dependency in my environment.rb file and then ran rake gems:install and rake gems:unpack. I also copied over my environment.rb file one line at ...

Paginate through a randomized list of blog posts using will_paginate

I want to give users the ability to page through my blog posts in random order. I can't implement it like this: @posts = Post.paginate :page => params[:page], :order => 'RANDOM()' since the :order parameter is called with every query, and therefore I risk repeating blog posts. What's the best way to do this? ...

How to rename the default identifier param "id" in Rails' map.resources()?

I like all the default routes that are generated by Rail's map.resources. But, there are cases where I would like to use a non-numeric identifier in my routes. For example, If have a nested route consist of users and their articles, a standard route could be written as such: map.resources :users, :has_many => [:articles] # => e.g. '/us...

In RoR how do I dynamically show and limit the number of characters allowable?

For example, the comments in SO shows the number of allowable characters remaining. Basically, how do I do that in ruby on rails? ...

recommended way or plugin to create google sitemaps for ruby on rails app?

Hi, I did a quick Google search and didn't see anything super-great to automate creation and updating of my google sitemap for the ruby on rails app. Any suggestions? ...

is there any way to see which route matched a request from the browser in Rails?

In my routes.rb file I have a number of routes. I would like to know which one got matched for any request a user may have made. For example, in routes.rb you have the following routes : map.connect ":controller/:action" map.connect ":controler/:action/:id" and if I have a controller named a and an action named first, when a user g...

Ruby on Rails - FCKEditor Absolute Image Path Ruby

I am using the FCKEditor wysiwyg editor, and was wondering if anyone figured out how to use the absolute path instead of relative path after you add an image in the editor? And if so, how. ...

rails replace path in string

I have a string that may have a path to a file. Example src="/folder/whatever". How do I replace that path with src="http://www.sitename.com/folder/whatever ? ...

Ruby On Rails Active Record question, related to has_one

I have a Show model that has_one :venue, which is accomplished with each show having a venue_id And my Venue model belongs_to :show However I am having a problem accessing the venue by doing show.venue Consider the following code where s is a Show instance logger.info("*********************") logger.info("#{s.inspect}") ...

Apache shutting down unexpectedly

Hello, I have a mongrel server running behind Apache. It works fine; however, every now and then the Apache server shuts downs seemingly by itself. I'm not sure if there is configuration issue or if it's an attack. Here is Apache error log: [Thu Apr 30 02:15:07 2009] [notice] SIGHUP received. Attempting to restart [Thu Apr 30 02:15:0...

What's the best way to programmatically output a file in the format of a Word document in Ruby?

I need to output a file in the format of a Word document from a Ruby-based web app (Rails/Sinatra) based on some textual content in the app. Is there library support in Ruby for creating and structuring a Word document? ...

Why the Rails.cache.read can't get anything in ApplicationController?

Hi~ I had a problam, Ruby on Rails Cache in ApplicationController. The data can't get,but it's exist. class ApplicationController < ActionController::Base before_filter :init def init @setting = Rails.cache.read("data/setting") if not @setting @setting = Setting.find_create Rails.cache.write("data/setting",@sett...

How do you call attr_accessible dynamically in Rails?

I have a rather unique class that allows its child classes to declare virtual fields. The child can declare virtual fields stored as XML by calling a method of the parent class like this: class Child1 < Parent create_xml_field ["readings", "usage"] end I have managed to get it working via a nasty work around. The create_xml_field me...

What's this &block in Ruby? And how does it get passes in a method here?

Saw this piece of code in a RoR book. This first one is from a View and the second one is a helper module. I don't understand how that &block and the attributes={} thing work. Can anyone guide me to a tutorial of some kind explaining this? <% hidden_div_if(@cart.items.empty?, :id => "cart") do %> <%= render(:partial => "cart", :object ...

Best practices on processing email sent to app specific address in rails?

Hello all, We would like to implement a feature by which users could send an email to an application specific address and we will parse the message and take certain actions on it, similar to 37signals's backpack (and probably some of their other apps). If anyone has done something similar, could you fill me in on how you did so? I'm un...

Weird characters being saved in my database...

Here is a screen shot of weird characters in my database. I know that this character combination is for a crazy apostrophe. Should I just let these characters stay in my database? Or should I strip them out and replace with normal apostrophes? If I should strip, is there on ruby function to ensure that all characters that save to my d...

Is there an easier way to make something display only in the non-error state? (Ruby on Rails)

I have some text/images that I only want to display in the normal state of a form -- that is, it hasn't been submitted, yet. If the user submitted the form, and it is returned to the browser with errors, I'd like to display something else. Currently, I'm using: <% if [email protected]? -%> # Leaving this area blank. <% else -%> ...

How to generate external secure form for clients in Rails

Hello, I'm using Ruby on Rails to make an application where businesses can create accounts and add information about their clients. I would like to be able to generate a form that they can put on their website to automatically enter the clients' info into their account. I know I might be able to do something like: <% form_tag my_site_u...