ruby-on-rails

Is there a way for a ruby on rails app to support web-based upgrades like Wordpress does?

I've been using Wordpress for awhile, it's installed on my own server, and one of the features I most love about it is how every time there is a new version it alerts you within the app's web-based admin and with one click I can upgrade the app. I don't have to get anywhere near a console. Personally I wouldn't mind updating manually, b...

Params becomming nil

Had some old code that on some condition would modify params. I believe it was working before (not 100%). We are now getting params set to nil whether or not the condition is met. The culprit is within the condition, I perform a params = tmp.dup. Even when the condition is false, this is causing an error in the update action. I was abl...

Best way to override named_scope for has_many associations in Rails?

Note: I'm using Rails 2.3.8, not 3. I have a Photo model with a default_scope: default_scope :conditions => ["published = ?", true], :order => :position Calling photo_album.photos returns all published photos ordered by position as it should. However, when looping through these photo albums in an admin panel to display the number of ...

How do I correctly add this model to a method?

This is a method that used to be in the controller and I think it makes more sense to make it a method to the Contact model: def colleagues company = Company.find(self.company_id) contacts = company.contacts.collect(&:full_name) contacts.each do |contact| colleagues = contacts.reject{ |c| c==contact } end ...

Standard Rails Gem for storing what User created/updated/deleted any Record?

What's the standard/best option out there for this kind of version control? The main thing I'm looking for is to track what user edited a record. I've seen these so far and am wondering what your take is: PaperTrail ActsAsAudited VestalVersions ...

failed to allocate memory while downloading large files in rails

Hii all, I am trying to downaload large file in rails using send_data function ,but getting error :failes to allocate memory and when trying to download in chunks ,getting only chunk size file only ,below is my code .. File.open(@containerformat.location,"rb"){ |f| @data = f.read(8888)} ext = File.ex...

using translation in the link_to in ROR

HI , In ROR , i m having a line like <%= link_to("NAME (#{@name})", user_path(@user, :in => :s)) %> i want to change the string NAME to t(:str_name) .. how to change it . when i change it , i am getting errors.. ...

In Ruby on Rails, if you have the association wrong in the models, will it affect your app if you only touch model.instance_variable?

That is, if you have all the has_many, has_one, belongs_to, and has many ... :through and has_many_and_belongs_to wrong, but your program only touch the model.instance_variable but not model.some_other_model # or model.some_other_model.some_method_or_variable will you app do anything wrong or do anything bad to the database? Th...

Rails Root directory path?

I recently migrated my application across servers and set up my directories a little. I ran into a problem where I had hard coded some paths, in particular, where I store all my attachments. I moved my attachment directory in app_path/../attachments/* Is there a variable that gets me my app_path, rails root directory, or whatever the...

Rails sends 0 byte files using send_file

I can't get send_file(Model.attachment.path) to work. It doesn't fail, instead, it sends a 0 byte size file to the client, the file names are correct though. This problem started happening after I did a big migration from Rails 2.3.8 to 3. There were a lot of other things that took place in this migration and I will try my best to deta...

link_to_remote doesn't work :with using jrails

I am trying to use link_to_remote with :with parameter so I can pass my parameters but I am using jrails and it seems it doesn't work. I use it another spot with jrails and prototype and it worked fine. Here is my code in jrails where I don't use prototype: <%= link_to_remote render(:partial => "back_button_text"), {:url => { :contro...

How can I check if an user is logged in or not in a Rails Metal?

I use Authlogic to log the user in. Inside a Rails Metal I want to check if the user is logged in or not. Just that, I don't care who the user is. I want to avoid touching the database so I should not do UserSession.find. My main doubts: Will making use of env['rack.session'] solve that? Where is that stored? Is that secure? I'm current...

is there a nicer oneliner for handling "unless somthing.nil? || something[:key].nil?"

Is there a way to make this one liner better looking? @var = params[:key1][:key2] unless params.blank? || params[:key1].blank? ...

Rails 3 generator's git option?

Hi, In rails 2.x I could pass on a --git option to ./script/generate to add files to git automatically after creation. However I have been unable to find such an option (or configuration) in Rails 3.0. Has this been removed or am I missing something? I tried researching this for a while but I am unable to find any reference. Thanks, P...

Insert &nbsp; in Rails with Nokogiri

Hi, i need to insert nbsp symbol in some places of the HTML, that comes from DB and will be displayed on the page. I do following: doc = Nokogiri::HTML( self.content ) doc.css("p").each do |p| p.content.gsub! pattern, "&nbsp;" end This resulting text contains nbsp, displayed as a plain text, but not a special symbol. I also trie...

How do I set attributes in an ActiveRecord Object before I save it?

Hi folks, I am trying to understand the Active Record Callbacks, but they do not work, like I want to. e.g. Model Checklist<ActiveRecord... attr_accessible :item1, :item2, :done # they are all boolean before_save :check_done private def check_done if item1 && item2 write_attribute :done, true else write_attribute :done, ...

Rails controller - redirect to website after create?

Hi Everyone, I am working on a basic app that has a public facing form (for enquiries) that anyone can fill in and submit. The results are then stored for the company to do what they want with. I have made sure that if the user is not logged in they can only access the create page, but once they submit the form, as expected, they are t...

Better data structure for multiple checks for a variable than if statements?

So, I have this block of code, and yes it looks ugly. Is there a better a data structure I can use to compare row.add,row.modify,row.delete and row.query with "Y" and call the get_role function? Note this block of code runs in a loop, hence the 'row'. if row.add == "y" role_ids << get_role("c") end if row.modify == ...

Is Ruby on Rails solution to async notify iPhone app of updates?

I starting to investigate whether Ruby-on-Rails will help solve my problem in some way? In short, I have a legacy Linux system and application which is reading and writing a collection of images. This application also uses a sqlite database to help refer to correct image files when required. What I'd like to do is have an iPhone and/or...

Identify which action is being called inside a model. Ruby on Rails

How do I come to know whether a create or any other action has been called from inside a model. Basically I am doing database logging and want to track whether a create or other actions are being performed. For doing the logging part I am using the concept of ActiveRecord::Observer. But there I am not able to find out whether the user i...