ruby-on-rails

Difference between attr_accessor and attr_accessible

Hi, In RoR, what is the difference between attr_accessor and attr_accessible. From my understanding, using attr_accessor is used to create getter and setter methods for that variable, so that we can access the variable like `Object.variable` or `Object.variable = some_value` I read that attr_accessible makes that specific variab...

rails: how do we call a variable that we can use in all the action that belongs to the same controller?

I would like to do something like using instance variables def index @balance=1000 enb def increment @balance+=1 end what kind of variable should i use? ...

Using haml or erb code in ModalBox causes afterLoad callback to not get called

I open a ModalBox with: =link_to_function "Add", "Modalbox.show('appt', {title: this.title, width: 600, height: 400, afterLoad: function() { alert('Content loaded') } });" This loads a haml file. When the haml file contains certain code, the callback never gets triggered. The same actually happens with .erb files as well. For example...

Running rake task from Windows scheduler

Hi, I have a custom Rake file, which I want to run periodically(every day). I am using a Windows machine, and have a .bat file, which basically does cd path/to/applicaion rake filename I am using the windows scheduler to run the bat file but it aborts, complaining that some gems are missing. However, when I start up a command promp...

How can I change the upload directory for paperclip on heroku to /tmp?

I need to upload files and then parse them using paperclip? Currently it is uploaded in the /system folder, which isn't allowed in heroku. I don't need the uploads to be persistent...I parse it and then store them. So I'd like to be able to save into /tmp and then parse, and then let it get blown away later. Thoughts on how to do thi...

In Rails Routes redirect /:controller_name to root?

I have a root path in my routes file: map.root :controller => 'games', :action => 'index' The problem is that if anyone goes to: http://domain.com/games it doesn't show the root, thus we're creating two urls for the same page. Is there a way to change any hit to http://domain.com/games to http://domain.com ? I'd rather not fiddle arou...

Using prototype to mimic html form

I have an html form generated by rails, so that when it's submitted, the rails controller can gather all the params for the rails object in one swoop with: @car_object = Car.new(params[:car]) which results in something like: @car_object.color = "red"; @car_object.make = "Honda" etc... But I also need to have the controller be able...

Creating migrations for SQL views in rails with boolean values

Iam using SQLite wit a view like this one: CREATE VIEW view_importaciones AS SELECT fecha_importacion, COUNT(DISTINCT(total)) - 1 AS total, COUNT(DISTINCT(errores)) -1 AS errores, estado FROM ( SELECT fecha_importacion, id AS total, 0 as errores, estado FROM marcas WHERE parent_id = 0 UNION SE...

Inventory SQL Query without UNION ?

I'm designing an inventory system, it has users, products, buy_leads, orders (authorized buy_leads), inputs and outputs. class Product < ActiveRecord::Base has_many :buy_leads end class BuyLead < ActiveRecord::Base belongs_to :product has_one :order end class Order < ActiveRecord::Base belongs_to :buy_lead belongs_to :user, ...

Rails -- Add a line break into a text area

Hi, I got a rails app where I can input a few paragraphs of text into my model. The problem is I dont know how to input any line breaks. I've tried to add " {ln}{/ln} ; {&nbsp} and {br}{/br}" but that only displays the html as text and no break. Is there anyway I can set it so the text area control will use any of the html I pla...

View emails sent

I have config.action_mailer.delivery_method = :test and use delayed_job. I run some code that places an email to be sent in a queue, then run rake jobs:work, but nowhere do I see the email that is sent out, and ActionMailer::Base.deliveries is nil. I'm just looking to debug and view the content of htese emails, how can I do so? ...

Atomic arithmetic in Rails

I need to perform some atomic arithmetic in Rails but the only way I've found to do it for single objects is via the crude update_all class method, e.g.: Account.update_all(["debits = debits + ?", amount], :id => id) With collection associations, the update_all class method should be usable as an association method, since the collecti...

default data in fckeditor with jQuery

I have following code in my view. = fckeditor_textarea("newsletter", "info", :toolbarSet => 'Simple', :width => '100%', :height => '400px') In my controller I have created an object for that which contains value. @newsletter = Newsletter.last But in display data is not loaded in fckeditor. So, how to do that? ...

Rails: Mapping Conflicting Routes by Detecting Param

Hey! I am trying to set up routes in a Rails application so that, depending on the type of parameter passed, Rails sends the request to a different action. I have courses which have an attribute state which is a string with a two letter state abbreviation. When a user visits /courses/1, I want Rails to display the show action in the co...

Exception when trying to upload file from Flex to Rails (using paperclip)

I'm trying to upload a Dynamically generated file from Flex (PNG image) to Ruby on Rails Server back end using the following code (from Flex on Rails book): public function save():void { var bitmapData:BitmapData = new BitmapData(width, height); bitmapData.draw(this); var ba:ByteArra...

Why can't records with piggy-back attributes be saved?

I recently run into a problem where records were marked as readonly. Checking out the documentation I found this: "Records loaded through joins with piggy-back attributes will be marked as read only since they cannot be saved. " Why not? My model looks like the following: class MailAccount belongs_to :account, :class_name => "Use...

Rails multipart Post Problem

Hi I have the below code in my controller <% form_for @picture, :picture, :url=>pictures_url, :html => { :multipart => true } do | form | %> <%=form.file_field :image%> <%=submit_tag 'Save'%> <%end%> which submits to the below controller class PicturesController < ApplicationController def create render :text=>1 end end ...

Rails collection_select

Manager :has_many :interns, :through => :assigns Intern :has_many :managers, :through => :assigns I am trying to create a new assign record. This is the assigns/new view where a given authenticated intern is creating a new association with a manager: # assigns/new.html.erb <% form_for @assign, :url => {:action => "create"} do |p| %> ...

Using MongoDB with Rails article

OK, So I know that MongoDB is the 'next big thing' in databases, and I'm exited. But i can't find an article that deals with how different it is using Mongo. Do we still have migrations? relatoinships? will has_one still work? And will we ever see support in activeRecord or is MongoMapper up to the job! I'm also wondering if they is a...

Search Logic removing records with no association from results when ordering by that association

I'm using search logic to filter and order my results but it removes records from my results when I order by a association and when that association is not always present for all records. For example say I have a user model which can have one vehicle model but does not have to, if I have a results table where you can order by the users ...