ruby-on-rails

How to filter by association count?

Let's say I have models that look like this: class Foo < ActiveRecord::Base has_many :bars, :through => :cakes has_many :cakes end class Bar < ActiveRecord::Base has_many :foos, :through => :cakes has_many :cakes end class Cake < ActiveRecord::Base belongs_to :foo belongs_to :bar end How would I get all foo...

How to programmatically list all controllers in Rails

I'm trying to build a RESTful app to actually manage many kind of configurable objects, so there are a large amount of "resource" types, and hence a lot of controllers. I'm still at the POC phase, so it will be nice if I can show all controllers in a first navigation page, so any easy way (programmable) to do that? ...

Preserving form submission through log in / sign up in Rails

Say I have a site like this (generic Q&A site) in Rails and I wanted this "ask" page w/ a text box to be the first page a user sees, even if he's not logged in. He enters a question, and on the 'new' method I check that he's not logged in, and bounced him to /session/new, where he can either log in or create a new account. Question is,...

authlogic openid + recaptcha + confirmed?

Hi all. Could you show me live code examples of integration authlogic-openid and recaptcha? I want to prevent users from registering using they own openid-servers to create multiple accounts and use it for spam. Also could you help me plz to understand - how to check confirmed? field on creation UserSession for openid registered users?...

Difference between <%= expression %> and <%= expression -%> on Ruby On Rails

Hi friends, I need to know what is the difference between <%= expression %> and <%= expression -%> on rails, please help me to make good foundation on Ruby On Rails ...

testing user log in process in rails

i am trying to create a simple login test, but cannot get past the follow_redirect. it says: TypeError: can't convert Symbol into String when it meets the 'follow_redirect'. Does it have anything to do with the fact that we are using https for the login process? i simply want to assert that the user is able to log in, and gets redirecte...

Rails paperclip problem

I have uploaded the video into my rails application by using thoughtbot-paperclip then the video is converted into "flv" format by using ffmpeg. For your reference here I specified some of my model sample code: model.rb: has_attached_file :source,:styles => {:thumb => "137x85>" } If i specified :url or :path option it doesn't worke...

Finding a text node in xml using xpath problem

I'm using rails and the Nokogiri parser. My xml is as below and I'm trying to get the 'Biology: 08:00' text into my view. <rss version="2.0"> <channel> <item> <title>Biology: 08:00</title> <description>Start time of Biology</description> <pubDate>Tue, 13 Oct 2009 UT</pubDate> </item> ...

getting comatose working with authlogic

I started using comatose to handle content on my site but am having problems using it with my existing authentication using a generic Authlogic config. In the readme he sites an example for configuring it with Restful Authentication and I'm wondering how I would do the same within a general Authlogic setup? #environment.rb Com...

row highlighting

Hello, I have inside a .erb file an HTML table which rows' classes are alternated using <tr class="<%= cycle('even_line', 'odd_line') %>"> This gives me a good visual style, but it is not enough. I want to change the row class on event mouseover. Is there any rails helper that gives me this functionality? I'm searching through the AP...

Rails: Make views editable by end-users?

Is there anyway I can make content in my Rails views editable by end-users? Such that they can make simple text changes on pages I permit them to without having me edit the HAML files myself? Thoughts? CLARIFICATION: I know about CMS systems, and I don't think that's entirely what I want. I want to maintain programatic control over my...

The Rails way to change URL based on variable? Routing and perhaps namespace related.

I have an images table with a nsfw flag. What's the best way to add nsfw and sfw to the URL? For example, if I have an image with an id=1 and nsfw flag is true, I want the URL to be /images/nsfw/1 if I have an image with an id=2 and nsfw flag is false, I want the URL to be /images/sfw/2 ...

Using searchlogic with will_paginate

EDIT Looks like I figured it out - I had to call paginate after the call to all from Searchlogic. I'm trying to use both of these tools to enable users to search contacts and return a paginated list (or the entire paginated list if they don't enter any search criteria). However I'm unsure of the proper way to chain them together, and w...

how to build plugin to connect to 3rd party API in Rails

This may seem a bit subjective but I am also looking for specifics on implementation if possible. The existing popular how-to's on creating plugins seem to assume you want to get into the guts ActiveRecord itself, or write an acts_as_* plugin, which is not really the case here. The requirement is to connect to a non-RESTful API at a 3rd...

How can I stop the password field being pre-populated on edit?

I have this problem all the time in my rails apps and I still need the correct solution. Whenever a user edits their own record the password field is being populated. I suspect its Firefox as setting @user.password = nil in the edit action doesn't help. The problem is the password confirmation isn't populated so validation fails due to ...

Warnings after freezing rails

I just froze rails to prepare for my first production release and now I get these warnings when starting my script/server on development: RAILS_ROOT/vendor/rails/railties/lib/rails/version.rb:3: warning: already initialized constant MAJOR RAILS_ROOT/vendor/rails/railties/lib/rails/version.rb:4: warning: already initialized constant MINO...

rails plugin for github

I need help on figuring out how to create a repository on github to store a rails plug-in that i wrote. ...

using Kernel#fork for backgrounding processes, pros? cons?

I'd like some thoughts on whether using fork{} to 'background' a process from a rails app is such a good idea or not... From what I gather fork{my_method; Process#setsid} does in fact do what it's supposed to do. 1) creates another processes with a different PID 2) doesn't interrupt the calling process (e.g. it continues w/o waiting f...

Access to current_user from within a model in Ruby on Rails

I need to implement fine-grained access control in a Ruby on Rails app. The permissions for individual users are saved in a database table and I thought that it would be best to let the respective resource (i.e. the instance of a model) decide whether a certain user is allowed to read from or write to it. Making this decision in the cont...

Modeling A Book With With Ruby on Rails Active Record

Im modeling an online book with ruby on rails. The book has chapters, each chapter has pages. Modeling this part is easy. What id like to do is keep track of what pages each user has read and when and whether they liked that page / whether the user completed the book. How would one recommend modeling keeping track of this in rails? Id id...