ruby-on-rails

Human readable URL causes a problem in Ruby on Rails

I have a basic CRUD with "Company" model. To make the company name show up, I did def to_param name.parameterize end Then I accessed http://localhost:3000/companies/american-express which runs show action in the companies controller. Obviously this doesn't work because the show method is as following: def show @company = Company...

Will_paginate Plugin on two objects on same page

Hello I am using will_paginte plugin on two objects on a same page. Like on stackoverflow. There is a profile page on which there is a pagination on two things QUestions and answers. I am having problem ie:-- when user is clicking on questions pagination page 2. answers page are also updating. The reason is both is sending a post vari...

FxCop/StyleCop equivalent for ruby on rails?

Is there any static code analysis tools for ruby on rails? I am looking for something on the lines of "tests vs code analysis" as well as rules based analysis provided by FxCop. As an additional feature, an integration with hudson would be cool too. ...

jQuery-Facebox - Popup is not working after repaint from AJAX

Hi I am having a set of Links in my page and I have attached the facebox jQuery functionality so that whenever a link is pressed, it will get a nice popup <a href="coach_selector_popup?day=<%= day %>&hour=<%= hour %>" rel="facebox"> Below is the script that I use for 'facebox'ing. <script type="text/javascript"> jQuery(document).r...

Set a session hash outside of RoR program?

Hi, I have had my new rails program up for a few days now. I'm running it on Ubuntu 10.4 with apache2 in another location than the website it's made for (it's a standalone database application for physiotherapists). The people I made it for now want me to deploy it to the public part of their website, only with one change. Those who open...

advance/basic and smartphone views in Rails

In a new Rail app I have to consider 2 differents user's type: basic and Advanced and I have to create smartphone views( unique view for both user's type). Then I have 3 view/layout: web advance web basic smartphone I already have the adv/basic flag for the user, and I followed the RBates tutorial http://asciicasts.com/episodes/19...

Ruby and RSS2 Feed not displaying image

Trying to create a simple RSS2 Feed that I could later pass on to FeedBurner but can't get RSS feed to display images at all. Also, from what I have read having xml.instruct! on top might cause IE to complain it's not a valid feed. Is this true? My Code looks like xml.instruct! xml.rss "version" => "2.0", "xmlns:dc" => "http://purl...

Rails: losing quotes in post parameters

I'm adding full-text search to my Rails site and allowing users to enter double quotes in the search input box. The problem is that the double quotes seem to get filtered out by Mongrel and so I never receive those quotes in the values of the params hash. How do I prevent this from happening? I'm running Rails 2.3.8. [Edit: added analy...

Specifying the range of supported Rails versions in a project

The config/environment.rb of my rails project contains this line: RAILS_GEM_VERSION = '>= 2.3.2' unless defined? RAILS_GEM_VERSION Which makes sure that only Rails of version 2.3.2 or greater will be used to run this app. Is there a way of specifying both the lower and the upper boundary at the same time? So that it would run, say, o...

Rails 'possible_controllers' problem

What I'm trying to do is pretty simple: generate a list of permissions based on controllers action defined roles. This works pretty nicely, the only problem, is that when I try to generate the list of rails controllers a second time (note: the first time works flawlessly) using: ActionController::Routing.possible_controllers I get a...

parsing # in rails uris

i am getting the following url information and need to parse it within rails. i already checked request and params but it is not there. the "#" character seems to f*ck up things. here's the url: http://foo.bar.me/whoo#access_token=131268096888809%7C2.5BRBl_qt4xJ08n88ycbpZg__.3600.1276880400-100001151606930%7C0kJ1K-qoGBbDoGbLx6s4z5UEa...

Form With Quantity doesn't seem to submit

Hey guys, I've been trying to understand the documentation and find an example, but I'm at a loss. This is just a submit form within the cart for updating the quantity. However, the updated quantity is not getting saved to the database -- it always makes the quantity 0. Please help. Form <% for line_item in @cart.line_items %> <% ...

Multiple has_manys of the same model

I have these models: Person has_many :messages_form_person, :foreign_key => :from_user_id, :class_name => :messages has_many :messages_to_person, :foreign_key => :to_user_id, :class_name => :messages Message belongs_to :to_person, :foreign_key => :to_user_id, :class_name => :person belongs_to :from_person, :foreign_key => ...

Rails: Link changes one attribute and then goes back

Rails newbie here. I have a list of items which can have a status represented by an integer (right now its just 1=active 0=inactive). What I want is next to each item a link to change the status of that item. So it might look like this: A nice item - Enable Another pretty item - Disable I can't think of how to make the link...

I dump data to a yml file, but can't load. Is it a "to_yaml" bug?

I dump the data from database to "test/fixtures/*.yml", but when I use rake db:fixtures:load, it complains the content of yml is invalid. Following is the content of my yml: answer_00016: id: 16 content: |- <% output_once :define_aaa do %> Your stuff here <% end %> Notice, the <% ... %> par...

Ruby on Rails: Javascript: How to grob focus when the text box appears

So, I have <script type="text/javascript"> function grabFocus(){ document.getElementByID("category_name").focus(); } </script> <div> <h1>New category</h1> <br/> <% remote_form_for :category, @category, :url=>{:action=>'ajax_create'} do |f| %> <%= f.error_messages %> <%= f.hidden_field :object_type %> <p> <%= f.text_field...

Rails nested form with nested resource: update belongs_to association when creating new has_many

Hey guys, I've been beating my head against a wall with a particular use case for nested forms (I'm using Rails 2.3.5). Essentially I have Project and Payment models that looks like this class Project < ActiveRecord::Base has_many :payments end class Payment < ActiveRecord::Base belongs_to :project accepts_nested_attributes_for ...

How does instance_eval work and why does DHH hate it?

At about the 19:00 mark in his RailsConf presentation, David Heinemeier Hansson talks about the downsides of instance_eval: For a long time I ranted and raved against instance_eval, which is the concept of not using a yielded parameter (like do |people|) and just straight do something and then evaluate what's in that block ...

Change Authlogic remember_me midsession

Is it possible to let the user change their remember_me status midsession? I.e. once the user is logged in non remember_me, is it possible to change to remember_me? This doesn't seem to work: # Set User Session To Remember ME Now @user_session = UserSession.find @user_session.remember_me = true ...

Formatting populated textarea, carriage returns, newlines, and HAML

When i populate a textarea with text using \r\n (carriage return - newline) the text is formatted improperly [UPDATE: \r\n is what is generated when filling out a textarea, i'm simply pulling from a database what was previously filled in. Also to note, in the production environment i don't seem to have this problem. END UPDATE] For examp...