ruby-on-rails

Associating two records after create in Rails

I'm working on an association between two models: class Person < ActiveRecord::Base belongs_to :user end class User < ActiveRecord::Base has_one :person end Many person records exist in the system that don't necessarily correspond to a user, but when creating a user you need to either create a new person record or associate to an...

How to cache view partial File.exists? checks for life of app in Rails

I'm rendering polymorphic records in a view by looping over the polymorphic records and choosing the appropriate partial to use for the polymorphic relationship. However when a user is administering the site each polymorphic record may (or may not) have a second (alternate) partial that should be used in that situation. So currently I'...

How to test named_scopes and search methods?

When I learned about proxy_options I started using it to test all my named scopes. But then I found myself simply copying the conditions hash straight from the model, so it wasn't really testing the correctness of the results: po = {:conditions => "foo.created_at <= '#{Time.now.beginning_of_week}'"} assert_equal po, Foo.created_this...

category structure

I am having trouble with some theory. I have a model called Promos, and I also have a model called Categories. I want the admin to be able to create set Categories from which the users will select in a dropdown to assign the Promo. So Promos will belong to a Category but the assignment ought to happen in the create. What is the recom...

Ruby on Rails- how to run a bash script as root?

What I'm wanting to do is use 'button_to' & friends to start different scripts on a linux server. Not all scripts will need to be root, but some will, since they'll be running "apt-get dist-upgrade" and such. The PassengerDefaultUser is set to www-data in apache2.conf I have already tried running scripts from the controller that do li...

displaying markdown in my textarea

I'm using BlueCloth to create html from markdown from the content my users enter into a textarea like this: def create @post = Post.new(params[:post]) do |post| body = BlueCloth.new(post.body) post.body = body.to_html end ... end This works great! I get the html stored in the database fine, But how do I show markdown in...

Cucumber new paths

The answer for this question should be trivial. Is there any way to get in to the show action path to a given AR object within cucumber paths.(I am using factories to set up test AR objects). I can refer in paths.rb new, edit and index paths but when it comes to show action it needs to specify the object and is there a way to refer that...

How to resolve "Something Went wrong" error in ruby on rails ?

Hi, I am using Ubuntu 9.04 I just installed ruby and rails in my system and the webrick server seems to have been installed without any errors. I created a "demo" rails app and created a controller 'say'. Then i created a view template 'hello.rhtml' I started the server and entered http://localhost:3000/say/hello in my browser. But t...

Agile Web Development with Rails 3rd Edition

it is showing me following error when i m opening http://localhost:3000/store **We're sorry, but something went wrong. We've been notified about this issue and we'll take a look at it shortly.** do anyone knows why it is showing me that error? ...

ruby on rails + iis7....

Hi, I'm attempting to setup Ruby on Rails on IIS7. I've been reading lots of guides, but this seems to be the only up-to-date version I can find: http://blogs.msdn.com/dgorti/archive/2009/06/17/ruby-on-rails-with-iis-7-reloaded.aspx Although I have set the correct network permissions (and even as a test given the everyone group full ...

How do I get a custom action to go to the right place?

I'm new to Ruby on Rails, and I'm sure I'm just missing something simple and stupid, but I can't figure out how to get my 'account/signup' action working. This is what I have in my routs file: map.connect ':controller/:action' map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format' map.root :controller => "...

Sort or Order Error Messags in error_messages (Rails)

Is there any (simple) way to get some control of the order in which a model's errors appear in the view? Ordering the rules does not seem to help whatsoever. ...

Rails SQL Left Join

My models: class Student has_many :grades has_many :courses, :through => :grades end class Grades belongs_to :student belongs_to :course end class Course has_many :grades has_many :students, :through => :grades end On my view page, for a student, I need to show all the courses and associated grades (if any) Student: Joe...

Does attr_accessible applied to user-related properties prevent user-data forgery?

I was looking at an authentication system which had this code: # prevents a user from submitting a crafted form that bypasses activation # anything else you want your user to change should be added here. attr_accessible :login, :email, :password, :password_confirmation, :first_name, :last_name I don't understand why attr_accessi...

What's mass assignment in Rails and does it need a special name?

I don't know if the term "mass assignment" is Rails-specific but I get the basic idea that mass assignment is when you assign values to a bunch of variables all in the same method. Is that a correct definition and why is there a special name for this? ...

Rails app (mod_rails) hangs every few hours

I'm running a Rails app through Phusion Passenger (mod_rails) which will run smoothly for a while, then suddenly slow to a crawl (one or two requests per hour) and become unresponsive. CPU usage is low throughout the whole ordeal, although I'm not sure about memory. Does anyone know where I should start to diagnose/fix the problem? Upd...

How best to work around PostgreSQL's stricter grouping

I am trying to convert from using MySQL to using PostgreSQL. I have this type of structure: User(entity) -> Follow -> Business(entity) -> Story The user needs to see all the news updates put out by the businesses they follow. The following query works great with MySQL because it simply shows all associated stories and groups by the sto...

Unable to load jars in a Rails app on Glassfish

Hi all, I have a Rails app that I'm trying to deploy onto Glassfish using the Glassfish gem, but it's unable to load the jar files I've written. I've tried passing the jars' path to jruby explicitly with jruby -I, but no luck. Any tips? Thanks a bunch ...

Best rails plugin for comments?

What is the best plugin or gem for adding comments to the ActiveRecord models in rails? Maybe there is one with ability to rate each comments with votes +1/-1 (like on youtube for example) and a cool view helper to display comments in a tree? ...

Application Dashboard View Logic

In my application I would like to provide a dashboard like screen when they login to get an overview of what is happening. I have about 4 models I would need to collect data from and sort them into order. My problem is knowing the action, so I can get specific fields per model. Here are a few ideas of how to go about it, but I feel they...