ruby-on-rails

Understanding Ruby on Rails ActiveRecord model Accessors

Hey there, I'm currently learning RoR and I've got the following problem: My Model, "DataFile", has a bunch of fields which I'd like to set from outside the Model, e.g. file = DataFile.new file.owner = 123 Now, as far as I know, I'd have to place an "attr_accessor :field" in my model, for every field that I'd like to modify from ou...

advice for structure and user access

Ok so I have acl9 in place and functioning, and my app structure thus far: Regions (which have) Locations (which have sales). Sales aren't important, basically just posts which will show on each location. I also have Users, which integrated with acl9 can be restricted and allowed based on role. What i need to to do is create companies...

Determine ruby version from within Rails

Is there a way to determine what version of Ruby is running from within Rails (either on the web or through script/console)? I have Ruby 1.8.6 installed but I've also installed Ruby Enterprise Edition 1.8.7-20090928 and want to ensure that it's using the right installation. ...

Help with RubyGems (the package manager).

I really need help with Rubygems (that's the package manager for ruby). Since I'm behind a proxy, I've given up all hope of it working automatically, so I had to download a lot of packages manually and install them for rails to install. Now, I'm getting an error message: Rails requires RubyGems >= 1.3.2 (...) Once again, I manually dow...

What is the best way to rotate logs for rails application

I have a 1GB slice from slicehost and I have 4 projects running on that box. All 4 applications are ruby on rails application. I was wondering what is the best way to ensure that log files are rotated. I would prefer to have 4 different log files one for each app rather than having one big log file for all 4 applications. I am running...

How can I refactor these unless statements to make the block more efficient?

I'm trying to add a "current" class to the following set of links based on if there is an "order" param in the URL. (ie. example.com/photos?order=views). I need some help refactoring this so it's not so burly. <% unless params[:order] != 'created_at' %> <%= link_to "Recently Posted", photos_path, :class => 'current' %> <% else %> ...

problem with friendly URLs routing by name instead of ID

I have a route in my code that looks like this: map.app 'applications/:title_header', :controller => 'apps', :action => 'show' I also changed my show method in the controller to be like this: @app = App.find_by_title_header(params[:title_header]) If I type in applications/title things work fine. If I type in applications/1 (valid I...

map.resource and naming convention for singleton

Hello, I am relatively new to ruby on rails, so this question might be easy. Rails does a lot of magic and I am not sure where to look up such things, because I don't know which part of the framework is to blame. I basically did the authlogic_example and fiddled around with the code afterwards. My routes.rb looks like this map.root ...

Force periodically_call_remote to fire immediately

I have a periodically_call_remote that I want to fire right away (as if the code was present without the setTimeout) as well as call periodically. Is there a nice way to do this use PCR, or do I have to roll my own? I'm using jQuery/jRails if it helps. ...

Validating length of habtm association without saving.

I have a user model with a HABTM relationship to groups. I do not want a user to be able to be in more than 5 groups, so would like to validate the length of the HABTM relationship. On the edit user page I have a list of checkboxes where the user can select the groups they want to be in (I'm using formtastic for the form). In my users...

How do I access the session object in a Rails performance test?

I am writing some performance tests and I want the user to be logged in: class CompaniesTest < ActionController::PerformanceTest fixtures :all def setup login_as(:cyrille) end def test_homepage get '/' end end The problem is: how should I implement login_as? I tried: private def login_as(user) @...

How to use a select to go to the Show action of another controller?

I'm trying to do something I thought easy and natural but I'm struggling.. On the homepage of my website, I want a select containing a list of users. After selecting a user and clicking on a button, it should go to the show action of the User controller page. I searched and found differents answers that I don't find very elegant: usi...

Combining two Rails applications into one

I have a couple of pre-existing applications which I need to run in "one" app. One is the application I want to use for authentication etc, whilst the other is another app that contains all of the business logic. Both apps have pre-existing authentication, and both have fairly complex user models. Is it possible to easily combine thes...

writing an attribute to my through table with validation ???

hi all I have been trying to do this for ages and can seem to grasp it. hope someone can help ? i have a 'message' model that has many through 'distribute' relationship to a 'contact_detail' model. basically a message can have many contacts associated with it and a contact can have many messages. I can get this to work and save it ...

Create a wizard that works with multiple Resources

I'm writing an app that has a "wizard" type input section. Think MS Windows Installers. I'm having a hard time figuring out how the most RESTful way to do this with rails. I can make it happen in a non-restful way (already did for version 1 of the app), but I'm trying to be a little more idiomatic this time around. Here's the situati...

Rails Validation | add class to surrounding <div>

Hi guys, Rails question. The default behavior for error validation is to fieldWithError-styled div around the input field like the following <div class="type-text" id="pre_negotiation_value_div"> <label for="contract_budget_holder">Budget Holder</label> <div class="fieldWithErrors"> <input id="contract_budget_holder"name="contract[bud...

mysql gem install can't find ri/rdoc definitions OS X 10.6.1

I installed the ruby gem for mysql and it looks like it installed correctly except for the documentation. I reviewed http://www.rhinocerus.net/forum/lang-ruby/587057-gem-install-mysql-returns-list-no-definition-xyz.html but it didn't help. Some notes, I am running on a 32-bit intel processor. Mac os x 10.6.1 Mac-Shaun:usr shaun$ s...

How can I scope acts_as_taggable_on_stereoids by Account ?

If I have my website logically split into accounts (eg. acme.mywebsite.com, xyz.mywebsite.com), how can I implement act-as-taggable-on-steroids and have the tags scoped by the current account ? To give little more details, if I am accessing acme I don't want to see tags from xyz subdomain. I have looked into act-as-taggable-on, but the...

Is validates_presence_of necessary of using validates_length_of?

In an ActiveRecord model, is it considered best practice/necessary to use validates_presence_of when also using validates_length_of? For example: class Company < ActiveRecord::Base validates_presence_of :name validates_length_of :name, :in => 5..30 end To me, it seems redundant. Having a length between 5 and 30 means that the a...

change the return of to_param by action? or, terribly broken edit action if perma-url is returned instead of id..

I did some stuff to have to_param return a perma-url so I'd have seo friendly links. Upon creation and update it will generate and return the perma-url in a to_param method that I put in the model. However this causing me some grief in other areas. I have a form that looks like this: <% @apps.each do |app| %> <% fields_for "[id][...