ruby-on-rails

Ruby on Rails - Cookie value displays only on refresh

I have a drop down in one of my views, allowing me to select the number of images on the page. I want to remember the selection on that page, so when the user comes back, the number of images displayed are what they selected last time around. To achieve this I am setting the cookie value from within the controller like this if cookies...

Ruby variable in :with of observe_field

I need to send a class name with my observe_field call so I can update the correct text_field (there are multiples on the same page) <%= observe_field "songlists_" + section.id.to_s + "_song_name", :frequency => 0.5, :url => { :controller => :songlists, :action => :get_artist }, :update => text_class , :with => "'song_name=' +enco...

named scope vs. find_by_sql (specific example)

Just out of curiosity, does anyone know a better way of building the following collection using named scopes (as opposed to find_by_sql)? @available = Workflow.find_by_sql([" SELECT workflows.id FROM workflows WHERE workflows.project_id = ? AND workflows.status < 5 AND ( workflows.created_by = ? OR workflows.id IN ...

Trying to use accepts_nested_attributes_for and has_and_belongs_to_many but the join table is not being populated

I am learning RoR and trying to use accepts_nested_attributes_for and has_and_belongs_to_many to submit information that would traditionally be two forms. I have read on some sites they are compatible, some sites they aren't compatible, and some sites don't know. As reference, I am using Rails 2.3.4. I tried modeling my solution from ...

Cucumber Cleanup

SO Folk, Anyone around these parts know if you can keep Cucumber from cleansing test data at the end of a run? I've a few tests that continue to fail and I'd like to have a look at the data backing those tests... Any ideas? Thanks! Cory Wilkerson ...

Rails' new_record? not reset (to true) if transaction is rolled back

So take the following test in Rspec: require 'spec_helper' describe Author do self.use_transactional_fixtures = false after(:each) do Author.destroy_all end it "should behave normal when using transactions" do my_author = nil begin Author.transaction do my_author = Author.new(:name => "My Name") ...

Restful Authentication: Allow logins from multiple computers?

Our Rails app is using Restful Authentication for user/session management and it seems that logging in to the same account from multiple computers kills the session on the other computers, thus killing the "Remember me" feature. So say I'm at home and log in to the app (and check "Remember me"). Then I go to the office and log in (and a...

How can you use Rails AuthenticityToken infrastructure to explicitly protect a GET action

Rails AuthenticityToken automatically protects POST/PUT/DELETE requests from CSRF attacks. But I have another use case in mind. I am showing a video on my site that I don't want to be embeddable on other sites. How this works is that my flash player sends a request for a signed URL from my CDN that expires in a few seconds. Up until ...

Rails // jquery ui.sortable // jq not sending request

There might just be an update i'm not aware of according to this post, but i have some trouble with the sortable; nothing get sent (neither firebug nor my controller get anything) - any browsers. On rails using this very good post Big thx for any info about it. ...

Send Facebook notification to user who registered on my site via facebook connect.

Let me start by saying facebook's developer documentation sucks. Bad. I'm using the facebooker plugin in rails to let users sign up through facebook connect. Now when certain things occur I want to send notifications to certain users through facebook. I heard some say that notifications must go from one user to another, but I've seen ev...

Do I need a banking license for this paypal-based ecommerce app?

The application will accept payments from users with paypal's Payments Standard. All of this money will be stored temporarily in the company's paypal account, and then redirected to some of the users involved in the transaction via their paypal accounts (we'd also keep a cut of this money). Would this implementation require a banking lic...

How would I do this JOIN in Rails?

Here's my SQL statement: SELECT * FROM `message_users` LEFT JOIN `messages` ON message_users.message_id = messages.id WHERE (message_users.user_id = 1 AND message_users.hidden = 0) AND message_users.last_read_at > messages.updated_at ORDER BY messages.updated_at DESC LIMIT 0, 20 How would I pull that off with proper ...

How could I implement the permit directive through database in rails-authorization-plugin, in a way that an admin user can change?

I'd like to control the permit method with something like this class SomethingController < ApplicationController permit :somerole end where ':somerole' is a field in the database linked to a controller and an action. Something that an user with priviledge can administer and change. Some Idea? ...

Writing own scaffold generator, exporting as a gem

I have created my own scaffold generator, now it's sitting in my ~/.rails/generator/scaffold directory. How can I make a gem in order to use my generator along other machines I'm using, without the need of copying the ~/.rails folder on every box ? I will push later the gem on Github ...

Ruby on rails relationships

I am extremely new to ruby and programming in general. In the copy, paste, and pray stage as I like to call it. I am trying to restrict access of editing posts and comments to the creator but when i create a post the user_id isn't populating in the database. thanks in advance for the help. routes map.resources :user_sessions map.res...

<li> only visible when parent has css class="current"

I have a list of categories called Taxons: The Rails code is here: <div id="taxonomies" class="sidebar-item"> <% @taxonomies.each do |taxonomy| %> <ul class="navigation-list"> <% taxonomy.root.children.each do |taxon| %> <li<%= ' class="current"' if @taxon and ([@taxon] + @taxon.ancestors).include?(taxon) %>><%= link_...

Rails 2.3.5 with rails_xss escaping content_for yielded content

Just upgraded Rails to 2.3.5 to get the lovely looking rails_xss plugin but I've noticed one big issue with it. Any content_for blocks are escaped when yielded. I've tried hacking it around by doing the either of following but they do not work: <% @content_for_foo.html_safe! -%> <%= yield raw :foo %> ...

Erubis block helper throwing error with concat

I have a couple of block helpers, here's a simple example of what I'm doing: def wrap_foo foo, &block data = capture(&block) content = " <div class=\"foo\" id=\"#{foo}\"> #{data} </div>" concat( content ) end I'm just trying out erubis and it's giving me the following error: You have a nil object when...

lowpro x non-ajax post in a rails application

Hi, i have a form, that because it has a upload file, i had to switch from ajax to iframe post to emulate an ajax. The problem is that it has a component with lowpro to hide and show a button with onmouseover and onmouseout. Everything work fine. The problem is that after that i submit the form, with iframe, after the page reload, the ...

Is there an easy way to combine memcache and a disk cache in a Rail app?

My Rails app uses memcache for fragment, action and other caching but has a long tail of infrequently accessed items so its hard to keep them all in the cache without making it really huge and gobbling up dozens of gigs of server memory. But my caching servers do have hundreds of gigs of free disk memory that is unutilized, as do my app...