[Rails] Re: Share code between unit and functional tests?

2009-10-11 Thread Andrew Bloom
You can add it to the test_helper.rb file and it will be included in all your default tests. Alternatively you could simply put it in a module (in a separate file in RAILS_ROOT/test and then "include" it in test_helper.rb or the individual test classes as you need. On Oct 11, 10:35 am, Marnen Lai

[Rails] Re: Calling a self controller path on method from view

2009-06-15 Thread Andrew Bloom
You can use that technique to do something like this in your helper: link_to("Link!", { :action => "blah", :controller => controller.controller_name }) You don't have to use named routes all the time. There are definitely times where the path hash is advantageous. On Jun 15, 9:05 pm, bill walto

[Rails] Re: Exception notifier and rails 2.3, does it work?

2009-04-30 Thread Andrew Bloom
Very strange. Have you checked postfix at all? I use ExceptionNotifier in 2.3 with no problems at all. On Apr 30, 1:25 pm, fausto wrote: > Hi, i've just installed exception notifier, set in the enviroment.rb > (i've tried also in an inizializer file and in production.rb in the > enviroments fold

[Rails] Re: Architectual question: Engine with all common models

2009-04-12 Thread Andrew Bloom
One issue with splitting the application into 3 will be consistency of deployment. If the models in the engine change you need to at a minimum run all the tests in all 3 systems, and possibly make updates, then find the time to deploy all 3. I know these situations are solvable, but I don't think

[Rails] Re: Sub controllers?

2009-04-01 Thread Andrew Bloom
You can use some inheritance and before_filters to handle this. class ApplicationController < ActionController::Base def load_panel_data @data = Data.all end end class OtherController < ActionController::Base before_filter :load_panel_data ... your normal actions ... end

[Rails] Re: will_paginate and SEO

2009-03-29 Thread Andrew Bloom
In your controller you can redirect to the same action without the 'page' in the querystring if it is equal to 1. def index redirect_to :action => 'index' if params[:page] && params [:page].to_i == 1 params[:page] ||= 1 # your normal code here end On Mar 29, 5:03 am, Aldo Italo wrot

[Rails] Re: prevent an object from being destroyed if it has related records

2009-03-29 Thread Andrew Bloom
You could always use inheritance. class Book < ActiveRecord::Base def destroy return super if page.empty? return false end end On Mar 29, 11:10 am, Neal L wrote: > This is a total noob question, but how do you prevent a record from > being destroyed if it has any related records.  I

[Rails] Re: Restful delete/destroy

2009-03-24 Thread Andrew Bloom
try changing the delete link to ad_path(ad) instead of ads_path(ad). On Mar 24, 10:30 pm, elle wrote: > Hello, > > I am sure this is a simple problem but for some reason I can't get it > to work. > I am trying to delete a record. My routes.rb has: > map.resources :ads > > ...the AdsController ha

[Rails] Re: Using record variable in routes

2009-03-08 Thread Andrew Bloom
# routes.rb map.connect "/projects/:project_slug/:image_slug", :controller => "images", :action => "show" # images_controller.rb def show @project = Project.find_by_slug(params[:project_slug]) @image = Image.find_by_slug(params[:image_slug]) ... end On Mar 8, 8:45 pm, David Lelong wrote:

[Rails] Re: 2 Issues - On load component hiding ; Separate find methods

2009-03-08 Thread Andrew Bloom
to answer your first question, hiding the comments by default is easy. simply add a "display:none" to the CSS for the divs you wish to be hidden initially. On Mar 8, 12:59 am, vishy wrote: > I have been working on developing a blog site using rails. This is my > first rails application, hence I

[Rails] Re: Simple search form with restful routes?

2009-03-06 Thread Andrew Bloom
ticket_path is expecting you to pass the ID of the ticket you are looking for. Something like this: ticket_path(123) Run 'rake routes' to get a good idea of what each named route is doing. What you need is something like this: # tickets_controller def search show end # routes.rb map.resource

[Rails] Re: restful_authentication with two models suggestion/help

2009-03-03 Thread Andrew Bloom
Just make a users table, and create a polymorphic relationship between users and students or teachers. Then, when the user logs in, check if they have a student or teacher record associated with them and redirect properly. On Mar 3, 1:59 pm, Tony Tony wrote: > Hi all, > > I'm working on trying t

[Rails] Re: Joining three objects uniquely using :has_many

2009-02-21 Thread Andrew Bloom
I'm not sure I'm 100% clear, but it sounds like you are saying that a Repair may only have one combination of Part/Product, and it just so happens that this combination implies a Level. To me the validation would be: class Repair < ActiveRecord::Base belongs_to :level belongs_to :product be

[Rails] Re: Helper

2009-02-20 Thread Andrew Bloom
Try something like this: def current_li(content, x) klass = x ? "current" : nil content_tag(:li, content, :class => klass) end On Feb 20, 3:55 pm, James Bond wrote: > How make a helper: > > If value X is true: print else > -- > Posted viahttp://www.ruby-forum.com/. --~--~-~--~

[Rails] Re: Click tracking for external links

2009-02-05 Thread Andrew Bloom
no standard exists as far as i know. you have 2 options as i see it. 1.) run each link through a redirect. something like: blah 2.) or use some javascript and implement an onclick handler on the link to fire an ajax request back to your application at work i had to implement something similar,

[Rails] Re: Help using a rake task to add items to my database?

2009-01-25 Thread Andrew Bloom
Try this and see what is printed: if @event.save puts "Event saved" else puts @event.errors.full_messages.inspect end What you're doing sounds right, most likely though you have a validation that is keeping the model from saving. On Jan 25, 4:44 pm, Sharon Machlis wrote: > Once a month

[Rails] Re: observer questions

2009-01-25 Thread Andrew Bloom
it depends on the specific callback in question. the list of available callbacks can be found here: http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html On Jan 24, 11:43 pm, Greg Hauptmann wrote: > Hi, > Re Rails observers, > (i.e.http://api.rubyonrails.org/classes/ActiveRecord/Obser

[Rails] Re: String split help

2009-01-24 Thread Andrew Bloom
"xxx | yyy | zzz | ddd".split(" | ") # => ["xxx", "yyy", "zzz", "ddd"] On Jan 23, 4:29 pm, Philip Hallstrom wrote: > > I have string: "xxx | yyy | zzz | ddd" > > > I need to split it to: "xxx", "yyy", "zzz" and "ddd", > > make link to every word like: xxx > > > So result must by: > > > from this

[Rails] Re: Shared templates across controllers

2009-01-20 Thread Andrew Bloom
Check out the docs for ActionController::Base#view_paths. You can probably monkey with that to get both controllers to look in the same directory. On Jan 20, 4:25 pm, "Brian Hogan" wrote: > Sure.  No, there really isn't. It's a convenience thing. Not having to > specify the template is a blessin

[Rails] Re: MVC architecture

2009-01-05 Thread Andrew Bloom
It would also be appropriate to place the ssh.rb file in the lib/ directory. Placing it in app/models/ is fine. It's just a matter of preference. On Jan 5, 10:10 pm, Valentino Lun wrote: > Dear all > > In the MVC architecture framework, the Model is actually communicate > with database. In my ra

[Rails] Re: How do booleans work?

2009-01-04 Thread Andrew Bloom
What Mike is hinting at is the way ActiveRecord abstracts database differences. MySQL and SQLite3 probably use different column types but this will appear transparent to the developer as ActiveRecord handles serializing and de-serializing the column data into Ruby objects. I am not a DBA, and I'm

[Rails] Re: Plugin not found: ["acts_as_list"]

2009-01-04 Thread Andrew Bloom
if the plugin is already installed in vendor/plugins there is no reason to install it with script/plugin. On Jan 4, 6:48 pm, Jason Newport wrote: > I am trying to install acts_as_list in a rails 2.2.2 project but when I > try the following:  ruby script/plugin install acts_as_list > > I get:  Pl

[Rails] Re: How to declare a member for a restful resource when it has a nested resource

2009-01-04 Thread Andrew Bloom
The collection and other options are just a hash being passed as parameters to the resources method. The ruby language defines all parameters before blocks in method calls. Try the following: map.resources :cities, :collection => {:manage => :get} do |cities| cities.resources :venues, :collect

[Rails] Re: Checking for Functional Site

2009-01-04 Thread Andrew Bloom
If you can run a cron script, don't worry about actually doing something in Ruby or Rails itself. Just write a bash script to check the output of the 'gem rails' command for the appropriate version number you use. On Jan 3, 1:11 pm, Michael Satterwhite wrote: > I have my rails sites hosted by Bl

[Rails] Re: Code refactoring is the key

2008-12-30 Thread Andrew Bloom
You can break up common methods and place them in modules. Then simply "include" the module in ApplicationController (or any other set or sub set of controllers as needed). On Dec 30, 10:39 am, vlain wrote: > After six month of development and a first release we decide to > refactor our applicat

[Rails] Re: 2.2.2 simple_captcha upgrade error

2008-12-29 Thread Andrew Bloom
I asked my boss what gem it was he determined we need to be on, he claims "pr", so I tried to install it and it fails to compile, so now im back to square one. I really thought I had this all sorted out a few weeks ago, maybe it was on a different computer. On Dec 28, 11:18 pm, An

[Rails] Re: 2.2.2 simple_captcha upgrade error

2008-12-28 Thread Andrew Bloom
It's not the postgres (psql) version thats the problem, its actually the ruby postgres gem that ActiveRecord uses to connect to psql. I will be in the office tomorrow and will check it out. On Dec 28, 10:48 am, Richard Schneeman wrote: > That does make sense given all i've read about this error,

[Rails] Re: 2.2.2 simple_captcha upgrade error

2008-12-27 Thread Andrew Bloom
It's actually a problem with the postgres gem. I ran into this the other day at work, if I remember correctly you just need to switch which gem you hav installed. Unfortunately I don't remember which one to use and I'm not at the office. On Dec 27, 11:57 pm, Richard Schneeman wrote: > So thanks

[Rails] Re: distributing a rails application

2008-12-17 Thread Andrew Bloom
why ignore the test dir? dont you want to share those? On Dec 17, 10:28 pm, Ryan Bigg wrote: > Github! > > All the entries from my .gitignore file: > > log/*.log > log/searchd* > tmp/* > db/*.sqlite3 > db/sphinx/* > config/database.yml > test > coverage > coverage/* > config/*.sphinx.conf > conf

[Rails] Re: Avoiding Clutter in views

2008-12-14 Thread Andrew Bloom
Don't forget about helpers. Helpers that take blocks are especially useful, it's a really easy way to conditionally display some content without cluttering the view. # Helper def is_authorized(action, resource, &block) yield if current_user.permission_check(action, resource) end # View <% is_a

[Rails] Re: Is Rails suitable for highly customized standard software

2008-12-13 Thread Andrew Bloom
I would say go for it. There are a number of ways to approach your situations. A simple solution might be to create plugins with models and controllers, and build a different app for each client, basically providing the views and configuration. More complex and powerful alternatives exist of cours

[Rails] Re: Optional route parameters for resource routes?

2008-12-09 Thread Andrew Bloom
map.resources :images, :member => [:500, :1000] will map to 2 methods in your controller, but I think you might have problems giving ruby method names that start with numbers. you probably just have to make a specially entry in your routes file, something like this: map.cached_image '/images/:i

[Rails] Re: Multiple polymorphism ?

2008-12-08 Thread Andrew Bloom
Maybe I'm missing something, but it doesn't sound like you need acts_as_taggable or single table inheritance. I think you will get the desired result by setting up the ObjectRelations model as follows: class ObjectRelations < ActiveRecord::Base belongs_to :linkfrom, :polymorphic => true belon

[Rails] Re: Does passing the params collection to a model break mvc?

2008-12-07 Thread Andrew Bloom
If you notice I only pass a section of the params has designed specifically to build the appropriate query, not the entire hash. On Dec 7, 5:22 pm, Leonardo <[EMAIL PROTECTED]> wrote: > You're passing unnecessary knowledge to your model. > It definitely doesn't need to know the controller and/or

[Rails] Re: Does passing the params collection to a model break mvc?

2008-12-07 Thread Andrew Bloom
Not necessarily. The params object is just a hash. There is no reason why you can't or shouldnt pass a configuration hash to a method. I do something similar quite often. One instance I find myself working with is XML API's that I must generate. Many options are available on the query string. To h

[Rails] Re: Using a model in a library

2008-12-04 Thread Andrew Bloom
Sounds like you just need a line like this in the top of the lib file: require 'app/models/aircraft' If its already loaded (ie: running script/server) nothing will change, but if its not already loaded (I don't use RSpec, but it sounds like its not autoloading classes) this should fix it. You mi

[Rails] Re: Subdomains with Rails 2.2

2008-12-03 Thread Andrew Bloom
The code to configure this is fairly trivial, try something like this in the controller(s) you need subdomain access. before_filter :load_account def load_account @account = Account.find(:first, :conditions => ["slug = ?", request.subdomains.first]) raise ActiveRecord::RecordNotFound unless @

[Rails] Re: Using a model in a library

2008-11-28 Thread Andrew Bloom
How and where are you executing the code in this lib from, rake task, script/console, etc.? On Nov 28, 12:10 pm, Christian Lescuyer <[EMAIL PROTECTED]> wrote: > Hi, > > I'm trying to verify that a parameter is an instance of a specific > class in Rails: > > def schedule(action, *args) >   if arg.

[Rails] Re: Emailing: lots of recipients + individual mails/attachments

2008-11-27 Thread Andrew Bloom
I don't understand your question, are you trying to find a way to mass mail people unique messages with unique attachments? On Nov 27, 12:08 pm, Tom Ha <[EMAIL PROTECTED]> wrote: > Hi there! > > What emailing solution (plugin, gem, script) can you suggest for the > following situation: > > - mail

[Rails] Re: How to wait and check for login to an external site

2008-11-27 Thread Andrew Bloom
check out the google calendar API docs, instead of using mechanize and scraping the page. http://code.google.com/apis/calendar/docs/2.0/developers_guide_protocol.html On Nov 27, 5:58 pm, kevin lee <[EMAIL PROTECTED]> wrote: > Hi I am working on a event calendar app that I would like a user to be

[Rails] Re: Named Route question

2008-11-27 Thread Andrew Bloom
You can make named routes for everything using the technique Phillip posted, you could rearrange your actions to be more restful (maybe a sessions controller, and map login to sessions#create, or move your default routes to a different position in the routes file (order is important here). On Nov

[Rails] Re: Where to initialize session variables?

2008-11-27 Thread Andrew Bloom
The solution you have seems like a fine answer to me. Simple, standard, and should be pretty easy for any incoming developer to understand. If youve got a method like the following then it probably isn't a big performance drain either. before_filter :intialize_session_stuff def intialize_session_

[Rails] Re: SQL in rails

2008-10-29 Thread Andrew Bloom
class Model < ActiveRecord::Base def raw_sql_query connection.execute("select name from #{table_name}") end end The above example will return something like this: [{:name => "A"}, {:name => "B"}] On Oct 29, 8:09 am, xxmithila <[EMAIL PROTECTED]> wrote: > Hi all.. > >    please give m

[Rails] Re: How to easily cache single AR object?

2008-10-22 Thread Andrew Bloom
If you dont want to get into memcache or other complex solutions you can do something simple like this: class StylesCache include Singleton def self.by_name(name) self.instance.by_name(name) end def by_name(name) return @active_style if @active_style && @active_style.name == nam

[Rails] Re: catch-all routing

2008-10-22 Thread Andrew Bloom
map.connect ":manufacturer_name/:model_name", :controller => "manufactuers", :action => "show" in your controller params[:manufacturer_name] and params[:model_name] should be available On Oct 22, 6:27 pm, Grayson Piercee <[EMAIL PROTECTED]> wrote: > I know this isn't all that Rails friendly but

[Rails] Re: setting session id for first visit

2008-10-22 Thread Andrew Bloom
At work we do something similar, although we dont have issues with the session_id using ActiveRecordStore. One approach you could take would be to create a new object (Visitor), and store the visitor.id in the session. Then use the before filter to load that Visitor on each request. Then, create a

[Rails] Re: Counting / Aggregation Queries

2008-10-21 Thread Andrew Bloom
named_scope is your friend class Download < ActiveRecord::Base belongs_to :file named_scope :between, lambda{ |start_date, end_date| { :conditions => ["created_at >= ? AND created_at < ?", start_date, end_date] } } named_scope :from_file, lambda { |file| { :conditions => ["file_id = ?", fi

[Rails] Re: Convert Illustrator file to HTML or CSS for programming on Ruby?

2008-10-18 Thread Andrew Bloom
check out this place: http://www.xhtmlized.com/ there are other companies that do the same thing, unfortunately this is the only name i can remember right now. On Oct 18, 10:44 pm, "Carla DeLuca" <[EMAIL PROTECTED]> wrote: > thank you > > On Sat, Oct 18, 2008 at 3:17 PM, Alex <[EMAIL PROTECTED]>

[Rails] Re: Running SQL file from inside rake task

2008-10-16 Thread Andrew Bloom
ActiveRecord::Base.connection.execute( ) On Oct 16, 3:19 pm, Freddy Andersen <[EMAIL PROTECTED]> wrote: > `mysql -uroot databasename < sqlfile.sql` --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Ta

[Rails] Re: ActionView: render a layout not in app/views?

2008-10-14 Thread Andrew Bloom
Quite often I'm tasked with doing something very similar. Check out my solution: class ExperiencesController < ApplicationController self.view_paths << File.join(RAILS_ROOT, "cms", "experiences") def show render :layout => "1/layout" end end requiring a folder structure like: RAILS_RO

[Rails] Re: Subdomains

2008-09-24 Thread Andrew Bloom
if the application isnt starting it probably isnt a controller, most likely something funky in your initializer (config/envrionment.rb) or your actual environment file (config/environments/development.rb) or possibly in a plugin you recently added. have you changed anything in those 3 locations re

[Rails] Re: Get Rid of Date in Migration Filename

2008-09-09 Thread Andrew Bloom
the advantage to the datetime based filenames over the simple integers is that it allows you to work in branches, make migrations and merge it all back together later without fear of conflicting migrations. why would you want to go back? On Sep 9, 8:45 pm, Trogdor <[EMAIL PROTECTED]> wrote: > I w

[Rails] Re: Configuring custom library

2008-09-08 Thread Andrew Bloom
ctiveSupport here is one big > Singleton?! That might be a way to solve it as this functionality > would perfectly fit in a Singleton. I will give it a thought > > Jan > > On 6 sep, 20:38, Andrew Bloom <[EMAIL PROTECTED]> wrote: > > > What I forgot t

[Rails] Re: Configuring custom library

2008-09-06 Thread Andrew Bloom
od, or use the extend method and refactor your module a bit. On Sep 6, 1:34 pm, Andrew Bloom <[EMAIL PROTECTED]> wrote: > if you are checking AccountSystem.account_system_type in your > controller what is the point of including it in ApplicationController? > If you plan to use it a

[Rails] Re: Web administration interface for Rails?!

2008-09-06 Thread Andrew Bloom
Have you seen: http://activescaffold.com/ ? It's not quite as automatic as Typus, but it seems easier to customize. Guess it depends on your needs. On Sep 6, 11:33 am, "Luiz Vitor Martinez Cardoso" <[EMAIL PROTECTED]> wrote: > Yeah, > > I'm looking for some admin page like django. I found only ty

[Rails] Re: Configuring custom library

2008-09-06 Thread Andrew Bloom
if you are checking AccountSystem.account_system_type in your controller what is the point of including it in ApplicationController? If you plan to use it as such, maybe you are better off making it a Singleton Class. If you actually want account_system_type to be a class accessor on ApplicationC