ruby-on-rails

Erb encoding problem in Rails 3

Hi guys, I'm using Rails 3. I want to display generated html fragment inside erb template <%= "<div>Foo Bar</div>" %> Rails encodes div tags. If I'm correct in Rails 2 <%=h cause encoding. Seems that it was changed in Rails 3. How can insert html fragment without encoding in Rails 3? Regards, Alexey. ...

Does the hoster has to support "Ruby on Rails" or "just Ruby" to run Rails?

Does the hoster have to support "Ruby on Rails" or "just Ruby" to run Rails? I know mainly PHP and ask myself if "Ruby on Rails" behaves to Ruby ... like "Zend Framework" to PHP: just a bunch of PHP files I can copy in my project folder and my hoster only needs to support PHP. I ask as my host only supports Ruby (but not Rails). If I c...

Does Rails 3 provide time based caching?

Hi guys, I need a timebased caching of certain pages. Cache for certain page should be cleared each 15 minutes. Is that possible? In http://edgeguides.rubyonrails.org/caching_with_rails.html manual I see that there is only manual cache clear methods, such as expire_page or expire_action. Regards, Alexey ...

what `update_attribute` return if it get failed?

Hi All, I have following piece of code @user = User.find(params[:id]) if (@user.activation_status == "active") #some code here @user.update_attribute('activation_status' ,'inactive') # Line 44 #send mail to user that his account is Acivated else end Is there any chance that Line 44 get fail because of any reason (for e...

Take control over email subject in rails

I need to change the subject of the emails on a low level. What rails does is encoding the subject as quoted in whatever encoding is set. What I need is to make it quoted but split into chunks of 64 byte, as hotmail doesn't really goes with the standards :/ How do I tell rails to take the subject as is? ...

Can i have multiple methods (post and get) allowed on an index action?

i would like an index action to be able to take get and post methods, is this possible and if so how? how do you write the route if in this case map.resources :content, :only => [ :index ] Many thanks ...

Ruby on Rails: How do I correctly define a method in the model to total up a column?

I'm trying total up all "amount" columns with a definition in the model like so: def self.total self.all.collect(&:amount).sum end With that, "Recipe.total" works as expected. However, I'm using a plugin that passes "Recipe.find(:all)", and I can't seem to pass that to the method to find the total. That is: Recipe.find(:all)....

How can I add a directory in GitHub?

I'm working through the Rails Tutorial. Anyone know how to add a directory in GitHub? see section 1.3.4 http://railstutorial.org/book?version=2.3#sec:version_control I can only get my README file and not the whole directory ...

Image appears as white, but when I click 'view image' it prompts to download it..

Why would that happen? Its ACL permissions are identical to all the other photos. These photos are hosted via an S3 bucket, but again, there's nothing different than any of the others. Here is the file URL: http://s3.amazonaws.com/hq-photo/root/system/images/340/resized_thumb/Osseo-Endo_System.png?1272485279 It's occurring with two...

Rails find conditions... where attribute is not a database column

I think it's safe to say everyone loves doing something like this in Rails: Product.find(:all, :conditions => {:featured => true}) This will return all products where the attribute "featured" (which is a database column) is true. But let's say I have a method on Product like this: def display_ready? (self.photos.length > 0) && (...

Constructing URL parameters in Rails 3

I am trying to use the following code to convert a hash of options (e.g. { :opt1 => 'a', :opt2 => 'b' } ) into parameters to be appended to a URL (e.g. example.com/page?opt1=a&opt2=b): ActionController::Routing::Route.new.build_query_string(options) where options is the hash. I get the following error: wrong number of arguments (0 fo...

How to test cookies state in functional tests in Rails?

How do I test a given controller action that uses cookies? How to set cookies in functional tests and how to get them? ...

Checkbox selection of database tables to include in Ruby on Rails view

I am working on a Ruby on Rails project where people can keep a diary for diseases or health conditions of their interest. They can (de)select multiple topics in their preferences with the help of checkboxes, and get disease specific questions and tracking options for their 'diseases of interest' on their personalized site. I am not very...

How do I organize/store a "type" field for a comments table?

My application has about half a dozen different types of items that a user can comment on (articles, photos, videos, user profiles, blog posts, forum posts). My plan right now is to have a single comments table in my database and then have parent_id and type fields in the table. The type field would just be a string and the contents of...

Rails rendering JSON data with Model Root

I've got some data in Rails that I want to render as JSON data. What I'm doing right now is simply finding all instances of a Model and calling render :json=>data. data = Data.find(:all) render :json => data However, Rails is including the model name in each JSON object. So my JSON data ends up looking like this: [{modelname:{propert...

Adding an rails activerecord association within a loop

I want to add a has_many through association to a activerecord model class for each symbol in an array. for example PeopleOrganisation::ROLES.each do |role| has_many role.to_s.pluralize.to_sym, :through => :people_organisations, :source => :person, :conditions => "people_organisations.role = '#{role.to_s}'" do def << (ob...

Best way to manage an S3 Bucket?

I have been trying for a month and a half now to transfer files and update ACL permissions. My bucket in question is 28gigs, and has over 45,000 objects in it. It generally takes three days to do it. I've tried the following : Bucket Explorer CloudBerry s3sync s3cmd s3 organizer s3fox And quite frankly, none of them can handle it. ...

Best Practice to abstract ActiveRecord model queries in Rails?

I'd like to extract out logic from the controllers to somewhere that it can be more DRY. What's the best way of handling something like the following in Rails? For instance, as opposed to having the query in the controllers, I could place it in the model: class SmoothieBlender < ActiveRecord::Base belongs_to :user def self.get_...

rails, genering markdown

I want to convert markdown to html... in views i have: markdown(some_text_variable) but i got error that undefined method markdown i added require 'BlueCoth' to enviroment.rb and i installed BlueCloth gem, so dont voting me down but help ...

Unexplainable "can't modify frozen object" exception

Hey, I have encountered a weird problem twice in the past 2 weeks and it's starting to piss me off. I have this very simple code : Rails.logger.debug "Is current_step frozen ? => #{@current_step.frozen?.inspect}" @current_step += 1 Has you can (or not) imagine, this is what is displayed on my console : Is current_step frozen ...