[Rails] Re: Share code between unit and functional tests?
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 Laibow-Koser wrote: > Joshua Muheim wrote: > > Hi all > > > I have the following helper that I use both in the unit and functional > > tests for my model Page: > > > class PagesControllerTest < ActionController::TestCase > > ... > > private > > def valid_attributes > > { :short_title => "Valid short title", > > :body => "Valid titleValid body", > > :parent_id => nil} > > end > > end > > > Is there a convenient way to remove this duplication and source it out > > to a file that is loaded by both the unit and the functional test files? > > With RSpec, you could use spec_helper; with TestCase, I don't know if > there's a standard location. > > However, in either case, there's a better solution to this particular > issue. If you use Machinist, these attributes could go into a named > blueprint. > > > > > Thanks > > Josh > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...@marnen.org > -- > Posted viahttp://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Calling a self controller path on method from view
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 walton wrote: > On Tue, 2009-06-16 at 03:02 +0200, Älphä Blüë wrote: > > I want to call/change this path based on the controller that calls it. > > Not sure if this is what you seek, but all views have access to the > controller / action that rendered them via controller.controller_name > and controller.action_name. > e.g.; > > <% if controller.controller_name == "rushing_offenses" -%> > some stuff > <% end %> > > HTH, > Bill --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Exception notifier and rails 2.3, does it work?
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 folder) > > ExceptionNotifier.exception_recipients = %w(m...@mail.com) > ExceptionNotifier.sender_address = %("Application Error" ) > ExceptionNotifier.email_prefix = "[ERROR] " > > and in the application controller > > include ExceptionNotifiable > local_addresses.clear (i've tried with and without this) > > deployed the app online with apache+passenger in production env, i > went to a page which thrown an error, but i didn't got any email. The > app itself can send emails (i use postfix, and for other emails from > the same app it works) > > Any idea why it doesn't work? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Architectual question: Engine with all common models
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 it's worth introducing them if you strive to keep all your interfaces (web, import, export) well separated. You could add something like app/importers and app/exporters and treat them like "controllers" for the alternate interfaces. Also, the use of modules and namespaces can be useful for situations likes this. On Apr 12, 6:45 pm, Marnen Laibow-Koser wrote: > Carsten Gehling wrote: > > I am maintaining a large Rails application, that consists of several > > "interfaces": > > > 1) The web interface (figures) > > 2) Import of data from external providers > > 3) Export of data to a large range of customers > > > It seems to me quite bloated to have all the code from 2) and 3) inside > > the web-application, since they functionally have nothing in common. The > > only reason for them being there, is that they also need the business > > rules implemented in the models. > [...] > > ii) Split my current application into 3 seperate applications - each > > only containing what is nessecary for its own uses: > > [...] > > I am not 100% sure that I'm correctly understanding the current > structure of your app, but if I am, my advice is this: you have one > application, accessible through multiple channels. Keep it that way -- > since it's one application, it probably shouldn't be broken down any > further from the user's point of view. Just keep everything modularized > well enough that the interfaces don't have much coupling to the models. > > (Of course, Phlip is liable to say something totally different, and if > he does, you should definitely listen to him, not me.) > > Best, > -- > Marnen Laibow-Koser > mar...@marnen.orghttp://www.marnen.org > -- > Posted viahttp://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Sub controllers?
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 In your layout you can now render a partial that is expecting the @data variable. before_filters are inheritable and configurable. http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html On Apr 1, 7:38 pm, Neil Middleton wrote: > it does partly - although I'm thinking more generically. For instance, let's > take the navigation for an app where it's state is dependant on some data in > the DB. I don't really want my page action to have to know anything about > the nav at all, as that's the layouts job to know what's on the page, but I > require a controller to provide the navigation with data. > From what I understand of partials these are kinda headless in that they > render a given variable, but don't have any interaction with the controller > per se. > > How do I go about rendering in this way? How do I let the layout kick of > code to render chunks of a page that contain data without contaminating my > page actions? > > Neil > > > > > > On Wed, Apr 1, 2009 at 6:01 PM, John Yerhot wrote: > > > Hey Neil, > > > Well, I'd go about it with a partial for the actual view part. If you > > simply need to just display it on a couple of actions, use a > > before_filter to call a method that sets variables only on those > > actions which require the submenu... then in your layout or view check > > that the variable is set and render the partial. > > > Otherwise, if you have a authentication system, set the variables in > > there. restful_authentication does this by providing logged_in? and > > current_user for you. > > > Hope that makes sense. :) > > > John > > > On Apr 1, 4:04 am, Neil Middleton > > wrote: > > > I'm pretty new to Rails and have an issue which I can't quite get my > > > head around as to the architecturally 'correct' way of doing it. > > > > Problem relates to what I kinda call sub-controllers. The scenario is > > > this: > > > > I have a series of pages, on which is a panel of some form containing > > > some information (think the user panel on gitHub top right). > > > > So, in my app, I have controllers that generate the data for the pages > > > and render out the responses which is fine, but when it comes to this > > > panel, it seems to me that you would want some sort of controller action > > > dedicated to generating this panel and it's view. > > > > Question is, how do you go about doing this? How do I render a 'sub > > > controller' from within a view? > > > -- > > > Posted viahttp://www.ruby-forum.com/. > > -- > Neil Middleton --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: will_paginate and SEO
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 wrote: > i have noted a problem in will_paginate : > > In a pagination, when go to pages geather than 1 value thath' ok, but if > you back to page 1 in the URL appear the parameter page=1 > this is bad for seo optimization, because engine view same page with > diffent URL. > how can remove the param only for the first page? > -- > Posted viahttp://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: prevent an object from being destroyed if it has related records
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. In my case, I have a > book model and a page model. A book has_many pages. > > How do I prevent book.destroy from destroying a book if it has > associated page records? Is there a :dependent option that would do > this? Do I need to do some sort of before destroy callback? > > Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Restful delete/destroy
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 has: > def destroy > @ad = Ad.find(params[:id]) > @ad.destroy > > respond_to do |format| > format.html { redirect_to(ads_url) } > format.xml { head :ok } > end > end > > ...and the index.html.erb has: > > <% @ads.each do |ad| %> > <%= link_to h(ad.name), ad %> [<%= link_to "Delete", ads_path > (ad), :method => :destroy %>] > <% end %> > > > But instead of destroying a record, it creates a new empty record. > Also, when looking at the url of 'Delete' I > gethttp://localhost:3000/ads.%23%3Cad:0x24681b8%3E > > TIA, > Elle --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Using record variable in routes
# 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: > I have two models in my application. One model is the project and it > has many images. I'd like to configure my routes so the URLs show the > names of the projects and images instead of the IDs. > > For example: > > /projects/brooklyn-loft > > would display detail about a specific project where "brooklyn-loft" is a > variable and unique for each project record, > > and > > /projects/brooklyn-loft/master-bathroom--2 > > would display detail about an image that belongs to the project and > "master-bathroom--2" is a variable and unique for each image record. > > Any ideas on how I would setup my routes to dynamically generate like > this? > > Thanks, > > David > -- > Posted viahttp://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: 2 Issues - On load component hiding ; Separate find methods
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 am fairly new to rails development. > Over the past week, I have encountered a few issues and hence I am > putting them all in one post here. Please feel free to comment on any > of the below mentioned issues: > > 1) On my blog post I have my blog entries and their respective > comments. The visibility of the comments is toggled using a link. When > my blog page loads, the comments are being displayed by default. > However I want to hide the comments on page load and show them only > when the "Comments" link is clicked. I am using rjs to toggle the > visibility. Is there a way to hide the comments on page load? The code > that I have is shown below: > > //Comments link: (blog.html.erb) > <%= link_to_remote pluralize(blogentry.comments.size, 'Comment'), :url > => { :action => 'show_comments', :entry => blogentry}%> > > //RJS Templates : (show_comments.js.rjs) > entry = params[:entry] > page.visual_effect :toggle_blind, "Comment_box_#{entry}" , :duration > => 0.5, :fps => 50 > > 2) I have also tried to categorize and archive the blog entries. For > that I am calling custom find methods. They are working fine and > everything is being done in the same method in the controller. Also I > have a single view file. However I would like to know if there is a > better way of doing this. Should I perform the find in separate > methods and have separate view files for each find (like separate view > for archives and categories)? Although I don't think that would be a > DRY implementation. The code is shown below: > > //page controller > def blog > @category = Category.find_by_name(params[:category_name]) > if (params[:category_name]) > @blogentries = Blogentry.find_all_by_category_id(@category.id) > elsif (params[:month] && params[:year] ) > start = Time.mktime(params[:year], params[:month]) > @blogentries = Blogentry.find(:all, :conditions => ['created_at> ? and > created_at < ?', start, start.next_month]) > > else > @blogentries = Blogentry.find(:all) > end > end > > //blog.html.erb > <% for blogentry in @blogentries %> > > > <%= h blogentry.title %> > > > <%=h blogentry.body %> > > > <% end %> > > //layout.html.erb (only the sidebar code with Archives and > Categories). > //This file provides the category, month and year required for > categorizing and archiving //respectively. > > > > CATEGORIES > <% for category in @categories%> > <% @entry = Blogentry.findforCatergoryid(category.id) %> > <%= link_to category.name.upcase + "(#...@entry.length})", > category_entries_path(category.name)%> > <% end%> > > > ARCHIVES > <% @entries_by_month.each do |month, entry|%> > <%= link_to month.strftime('%B %Y').upcase, > archive_path > (month.strftime('%Y'), month.strftime('%m'))%> > <% end%> > > > > Any help here will be be greatly appreciated. > > Thanks, > vishy --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Simple search form with restful routes?
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.resources :tickets, :collection => { :search => :post } You can now GET or POST to /tickets/search or tickets_search_path. On Mar 7, 1:05 am, Jl Smith wrote: > What am I doing wrong? I just want to create a simple form where I can > enter the ID of a model and it take me to that model. I'm trying to > place the form in the application layout, so I can use it from anywhere > in my app. I'm using restful routes only. I keep getting this routing > error when trying to create the form: > > ticket_url failed to generate from {:controller=>"tickets", > :action=>"show"} - you may have ambiguous routes, or you may need to > supply additional parameters for this route. > > Here's my resource declaration (routes.rb): > > map.resources :tickets > > Here's my "show" method in tickets_controller: > > def show > begin > @ticket = Ticket.find(params[:id]) > > respond_to do |format| > format.html # show.html.erb > format.xml { render :xml => @ticket } > end > rescue ActiveRecord::RecordNotFound > logger.error("Attempt to access invalid ticket_id => > #{params[:id]}") > flash[:warning] = "You have requested an invalid ticket." > redirect_to tickets_path > end > end > > Here's the form_tag I'm trying to use: > > <% form_tag ticket_path, {:id => 'jumpbox', :method => :get} do %> > > Enter a ticket number: > <%= text_field_tag 'id', nil, :size => 8, :class => "textbox" %> > <%= submit_tag 'Go', :name => nil %> > > <% end %> > > Thanks for any help! > -- > Posted viahttp://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: restful_authentication with two models suggestion/help
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 to create a login system via subdomains for a > teacher/students. > > I have two models at the moment. teacher.rb and student.rb. The fields > in both tables are almost identical. Now I've come add > restful_authentication and I realize this could be a pain with two > tables. I basically want to have one login screen where both the teacher > and/or student can login to the site. If it's a teacher they can access > teacher specific pages/data and students will see student specific > pages/data. > > Is it better to combine both teachers AND students into one table (users > table for example)? Or is there a way to keep both tables and still use > restful_authentication? > > Many thanks. Let me know if you need any more code or specifics. > > -Tony > -- > Posted viahttp://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Joining three objects uniquely using :has_many
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 belongs_to :part validates_presence_of :level_id, :product_id, :part_id validates_uniqueness_of :part_id, :scope => [:product_id] end Assuming I understand the problem, I think your confusion stems from the fact that the level isn't part of what defines a Repair, its simply an attribute of the Repair. It is really the Part and the Product that you should be concerned with. On Feb 21, 7:24 pm, Evan wrote: > I just tried this code and was still able to create records with > different levels for the same part/product combination. > > class RepairClass < ActiveRecord::Base > belongs_to :level > belongs_to :product > belongs_to :part > > validates_presence_of :level_id, :product_id, :part_id > validates_uniqueness_of :level_id, :scope => > [ :product_id, :part_id ] > end --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Helper
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/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Click tracking for external links
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, ive used both options successfully, each has its advantages/disadvantages. for example, #2 wont provide tracking if the user disables javascript. On Feb 5, 1:08 pm, Shannon wrote: > I'm new to Rails. I have an application with a group of external > links . I would like to track the > first time someone clicks on one of those links in my DB. What is the > standard "Rails" way to do something like this? > Thank you in advance --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Help using a rake task to add items to my database?
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 or so, I'd like to pull data from an RSS feed and add it > into my database. I've written a rake task that properly reads the > feed, parses it and assigns the correct information to new instances > of my @event model - when I run the rake task and have it print out > the various @event attributes, they're correct. However, when I > include the command @event.save nothing happens. > > In fact, when I added this code > > if @event.save > puts "Event saved" > else > puts "Event not saved, bummer" > > I got "Event not saved, bummer" > > Is it possible to use a rake task to add entries to my application's > database? If so, any suggestions as to what I might be doing wrong? > I'm testing this in my development environment, and I start my task > definition using > > task (:parse_info => :environment) do > > Any suggestions would be greatly appreciated. Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: observer questions
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/Observer.html), can > anyone > clarify: > > Question - Does the call back for a registered observer occur AFTER or > BEFORE the database transaction has completed? (e.g. if I issued a manual > rollback call in an observer callback method would it work or be too late to > trigger the rollback) > > -- > Greghttp://blog.gregnet.org/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: String split help
"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: "xxx | yyy | zzz | ddd" to this: > > > "xxx, yyy, zzz > a>, > href="ddd">ddd" > > > How can I do it? > > "xxx | yyy | zzz | ddd".split()map{}join() > > I'll let you figure out what goes into the () and {}'s :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Shared templates across controllers
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 blessing in most cases. Thing is, you could > probably do simething interesting with before / after filters. > > On Tue, Jan 20, 2009 at 4:09 PM, admanb wrote: > > > Actually, I got that part pretty well solved by just changing > > everything to "widget." :) > > > The part I'm wondering is if there's some way to re-route most of a > > controller to a different set of views than the standard default. > > Right now every action ends with "render :template => 'widget/ > > action_name'" but I'm curious if there's a better way. > > > -Adam > > > On Jan 20, 2:03 pm, "Brian Hogan" wrote: > >> I can think of a few things off the top of my head - one way is to > >> have one RJS file that looks like this: > > >> page.visual_effect :toggle_slide, "hidden...@object}_form" > >> page.visual_effect :toggle_slide, "add...@object}_testimonial}_button" > > >> And in each controller action, right before rendering the RJS, do this > > >> @object = "testimonial" > > >> or > > >> @object = "service" > > >> Basically, use instance variables (or another mechanism) to make > >> things available to the RJS template just like you would with anything > >> else. > > >> Heck if you have @service or @testimonial there, you could generalize > >> it more by using the same variable for each - �...@thing > > >> then do �...@thing.class.downcase to get "testimonial" or "service" > > >> How does that sound? :) > > >> On Tue, Jan 20, 2009 at 3:42 PM, admanb wrote: > > >> > Hey all, > > >> > Here's my situation: I have a pair of controllers with associated > >> > models (called Services and Testimonials) that are quite similar. > >> > Because their CRUD behavior is executed via AJAX, the "templates" for > >> > the actions are all short .rjs files. Now, because of the similarity > >> > of the models, most of the templates are exactly the same, with only > >> > the object names changed. That is, where one looks like this: > > >> > page.visual_effect :toggle_slide, 'hidden_testimonial_form' > >> > page.visual_effect :toggle_slide, 'add_testimonial_button' > > >> > The other looks like this: > > >> > page.visual_effect :toggle_slide, 'hidden_service_form' > >> > page.visual_effect :toggle_slide, 'add_service_button' > > >> > Obviously there's no reason these should be separate. My question is, > >> > what's the best way to set these up as shared templates? Both of the > >> > controllers inherit from a third controller (Brochure) because of > >> > shared authentication behavior. But the only way I can think of to > >> > share templates is something like this: > > >> > Put template files in /views/brochure. > > >> > At the end of each action, explicitly render the template. i.e. > > >> > def new > >> > ... > >> > render :template => 'brochure/new > >> > end > > >> > Is there a better way that I'm missing? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: MVC architecture
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 rails project, there is a model/ssh.rb that is not > connect with database. Is it a good practice for this arrangement in my > project? Am I violate the rules of MVC architecture? Or is it better to > move all the codes from models to controllers? What do you think? Thank > you. > > models/ssh.rb > $LOADED_FEATURES[$LOADED_FEATURES.length] = > 'net/ssh/authentication/pageant.rb' > require 'net/ssh' > > class Ssh > > def self.execute(cmd) > ssh=Net::SSH.start("ahnibm71", "testlib", :port => 19207, :paranoid > => false, :auth_methods => ["publickey"], :passphrase => "hellokitty", > :keys => ["C:/testing/id_rsa"]) > output = ssh.exec!(cmd) > ssh.close > if output.nil? > return "NULL" > else > return output.gsub("\n", "") > end > end > > end > > controllers/ssh_controller.rb > class SshController < ApplicationController > def main > end > > def test > render :text => Ssh.execute(params[:command]) > end > > end > -- > Posted viahttp://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: How do booleans work?
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 sure it varies from DB vendor to vendor, but I would have to assume that the ActiveRecord Developers chose the most appropriate column format (int(1) vs boolean) for each supported database. On Jan 4, 7:01 pm, James Byrne wrote: > Mike Chai wrote: > > I'm a little confused as to how booleans work in Rails. Which is > > better in the database? boolean or int(1)? True == 1 and False == 0, > > right? Using SQLite, I tried to set a value to true inside the > > database but it gave me an error. MySql didn't, so I had to switch to > > int(1) for it to work. Is this just how it is? > > No. True == anything other than nil or false > False == False > > DBMS have their own specific ways of handling booleans. The DBMS > adapter handles converting that to a Ruby form. > -- > Posted viahttp://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Plugin not found: ["acts_as_list"]
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: Plugin not found: ["acts_as_list"] > > I had to download the acts_as_list plugin from the github because it > isn't included in Rails 2.2.2. > > The files are in my vendor/plugins/acts_as_list folder so I have: > > lib/active_record/acts/list.rb > README > test/list_test.rb > init.rb > > What am I doing wrong here? > > TIA > -- > Posted viahttp://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: How to declare a member for a restful resource when it has a nested resource
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, :collection => {:transfer => :any} end On Jan 4, 8:17 pm, Raj wrote: > Currently my routes.rb looks like this. > > map.resources :cities do |cities| > cities.resources :venues, :collection => {:transfer => :any} > end > > Now I have a need to declare something like > > map.resources :cities, :collection => {:manage => :get} > > But since I have a nested resource for cities I am not sure what the > syntax is to declare a collection on cities? > > Thanks in advance. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Checking for Functional Site
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 Bluehost. While they are in many ways an > ideal host for developers, they have one very major problem. > > Their sysadmins periodically change the Rails installation without any > warning to users. The result of this is that the sites periodically > break - and we get no warning that this is going to happen. I don't > fault them for updating the installation - rails is pretty new > technology after all. By not letting us know what's happening, however, > our sites can go down without warning. The only way to determine whether > or not they've done something is to actually connect to the site and see > whether or not it is still working. I've complained to them about this > repeatedly ... their normal response is simply to ignore the complaint. > > Is there some way to do an autocheck of the system to see if anything in > the rails installation / configuration has changed? If there is, I could > set this up as a cron job and do a manual check when I determined that > something had changed. This would also minimize the distortion of the > logs from the hits from my check. > > Thanks in advance > ---Michael > -- > Posted viahttp://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Code refactoring is the key
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 application. Since it was my first Ruby/Rails application > there are a lot of horrible things inside it. > > And now? Some general hints? > > I start with 2 simple questions: > 1 - Where I put some common methods? Inside application.rb > (controller) is ugly... > 2 - In order to make skinny controller I write a lot of class method > inside the model, maybe too much? Is this a common practice? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: 2.2.2 simple_captcha upgrade error
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, Andrew Bloom wrote: > 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 > s.net> wrote: > > That does make sense given all i've read about this error, thanks a > > bunch!! I'm not in too much of a hurry to play wih 2.2.2, if its not too > > much trouble whenever you get back to the office, could you let me know > > what version of pgsql worked for you ( so i'm not just shooting in the > > dark) ? > > > Right now i'm running 8.3.3 and if memory serves me correctly i had too > > much trouble directly installing the gem, so I used mac ports. I tried > > installing 8.2 from ports and wasn't able to, i'm assuming whatever > > version i end up with, i'll have completely uninstall 8.3.3 first if i'm > > using ports ? > > -- > > Posted viahttp://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: 2.2.2 simple_captcha upgrade error
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, thanks a > bunch!! I'm not in too much of a hurry to play wih 2.2.2, if its not too > much trouble whenever you get back to the office, could you let me know > what version of pgsql worked for you ( so i'm not just shooting in the > dark) ? > > Right now i'm running 8.3.3 and if memory serves me correctly i had too > much trouble directly installing the gem, so I used mac ports. I tried > installing 8.2 from ports and wasn't able to, i'm assuming whatever > version i end up with, i'll have completely uninstall 8.3.3 first if i'm > using ports ? > -- > Posted viahttp://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: 2.2.2 simple_captcha upgrade error
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 to Craig, i got up and running on rails 2.2.2, though now i'm > dealing with a whole new can of worms. I've done a good bit o searching > and haven't found any solid leads. I'm using the simple_captcha plugin > on my site, and all is well until i call that plugin. > > http://www.pastie.org/347721 > > ActionView::TemplateError (undefined method `transaction_status' for > #) on line #43 of > app/views/forms/_slang_form.html.erb: > 42: > 43: <%= show_simple_captcha %> > 44: > 45: <%= @f.submit "Submit" %> > 46: > > The plugin works great in 2.1.0, Has anyone seen anything like this > before?? > -- > Posted viahttp://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: distributing a rails application
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 > config/deploy.rb > > - > Ryan Bigg > Freelancerhttp://frozenplague.net > > On 18/12/2008, at 2:55 PM, Little Known wrote: > > > > > What are the standard best practices for sharing your rails > > application > > on the web? > > > As far as I can tell, you just delete the logs directory and clear out > > the database.yml > > > What am I forgetting? > > -- > > Posted viahttp://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Avoiding Clutter in views
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_authorized(:edit, @user) do %> <%= link_to "Edit", edit_user_path(@user) %> <% end %> On Dec 13, 3:52 am, Robert Zolkos wrote: > Hi Rishav, > > The cleanest way is to try and move as much logic into the models and > controllers( depending on the context) and then moving a lot of the > repetitive view logic into partials. > > There is an excellent video on this on > RailsCastshttp://railscasts.com/episodes/55-cleaning-up-the-view > > Hope this helps. > > Rob > > On Dec 13, 4:45 pm, "Rishav Rastogi" wrote: > > > Hi, > > > I have seen that when using rails for big applications especially the ones > > with a lot of dynamic content. for example: profile pages in social network > > apps, newspaper websites etc. > > > The Views in such rails apps seem to have a lot of clutter, lots of render > > statements, 'if' statements etc.etc. Is there a way to avoid it or cleaner > > way to do it. > > > Thanks, > > Rishav --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Is Rails suitable for highly customized standard software
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 course. On Dec 13, 5:23 am, Andy Meyer wrote: > Hello, I am working in a small software company. We are developing > business applications for a very niche industry. > At the moment our software products are mainly fat client windows > applications which are accessing different kinds of database servers. > Now we plan to slowly move to web applications. We do not host the > applications for our customers, so it is necessary that we ship a > complete solution which is deployed at the customer site. > In total we will have about 20 to 40 customers deploying our web > application. > > Unfortunately every customer needs a specific customized user interface > and sequence of dialogues, but the general business logic is the same. > > So my question: Is Ruby on Rails capable for this kind of requirements? > > A colleague of me has already begun to develop a complete new web > application framework in pure java and servlets without using any > existing web application framework technology. He has almost no > background in web applications and is doing it all alone. > My thinking is that this strategy is a big mistake. In 2008 it is > essential to use a mature web application framework for a small company > with not more than 3 web developers. > Developing a own new framework makes no sense at all. Especially for a > small company with a very niche market. > > Now I am looking for convincing arguments for a discussion with our > boss. > Any help would be very much appreciated. > Regards, > Andy > -- > Posted viahttp://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Optional route parameters for resource routes?
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/:id/:size', :controller => "images", :action => "show" in your show method just check for the presence of :show in the params and respond appropriately. On Dec 9, 3:23 pm, Ben Johnson <[EMAIL PROTECTED]> wrote: > I have the following URL: > > /images/1.jpg?size=500 > > Where images is a resource setup via map.resources :images. I want to > take advantage of caching, and caching ignores parameters. So I need to > make size optional in the url: > > /images/1/500.jpg > > Something like that where the size can be built into the URL. I looked > through all of the map.resources documentation and couldn't find > anything to do this. Any ideas how I can accomplish this? > > Thanks for your help. > -- > Posted viahttp://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Multiple polymorphism ?
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 belongs_to :linkto, :polymorphic => true end class User < ActiveRecord::Base has_many :objectrelations, :as => :linkto has_many :objectrelations, :as => :linkfrom end On Dec 8, 5:39 am, Vincenzo Ruggiero <[EMAIL PROTECTED] s.net> wrote: > Hello all, > > Let me explain a fairly complex problem, I am blocked > and if someone could give me a boost I can thank him > enough! > > The concept: > - > I have a series of tables in DB (users, functions, expertize, ...) > > I want to put in place a system that would allow me to link these > different objects between them in a very flexible one > table. > > My idea: > - > Create a table "objectrelations" containing the following fields: > > id > linkfrom_id > linkfrom_type > linkto_id > linkto_type > created_at > updated_at > stopped_at > > # 1 record objectrelations: > id: 1 > linkfrom_id: 1 # User ID = 1 > linkfrom_type: "User" > linkto_id: 1 # expertize ID = 1 > linkto_type: "expertize" > created_at: now () > updated_at: now () > stopped_at: NULL > > The problem: > -- > This works well in DB, it allows me to create links between > different objects, back links, to end a relationship > (via the column stopped_at) without removing the link DB (it keeps a > history) ... > > As against, I don't find how to implement this model in > Rails (in models). > > I think I understand that I will use the polymorphism, > the "Through Associations" or "Single table inheritance" but I don't > know how. > > I looked at the side of "acts_as_taggable", they use a system > similar but only in one direction (any object -> > tags). Unfortunately, here I must be able to link anything with > anything ... > > Does anyone have an idea to help me? How should I do this ? > > Thank you > -- > Posted viahttp://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Does passing the params collection to a model break mvc?
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 the action > it's being called from. And this information is by default in the > params hash of any given controller action. > Thus, it's considered a bad practice - bad design. Your objects should > assume as little as possible about any other structure on your > application. > > -- > Leonardo Borgeswww.leonardoborges.com > > On Dec 5, 4:09 pm, "blinking bear" <[EMAIL PROTECTED]> wrote: > > > I want to pass the params collection from the controller to the model to > > parse filtering and sorting conditions. Does having a method in the model > > that takes the params from the controller break MVC? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Does passing the params collection to a model break mvc?
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 handle this I use a pattern similar to the example below: #Controller @models = Model.collection_for_api(params[:model]) render :xml => @models #Model def self.collection_for_api(opts = {}) # assemble a bunch of named scopes based on opts end On Dec 5, 9:09 am, "blinking bear" <[EMAIL PROTECTED]> wrote: > I want to pass the params collection from the controller to the model to > parse filtering and sorting conditions. Does having a method in the model > that takes the params from the controller break MVC? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Using a model in a library
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 might need to play with the path and do something like this: require File.dirname(__FILE__)+'/../app/models/aircraft' On Nov 29, 7:45 am, Christian Lescuyer <[EMAIL PROTECTED]> wrote: > Thanks for your answer: I tried to run the app in the browser: it > works! > So it doesn't work in RSpec. I didn't try the code in the browser at > first as I'm trying to do TDD. Still stuck there, though. > > Christian --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Subdomains with Rails 2.2
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 @account end On Dec 3, 10:16 am, Perry D <[EMAIL PROTECTED]> wrote: > I'm pretty new here, but if anybody had ideas on how to go about using > subdomains for accounts within Rails 2.2. I had seen the subdomain-fu > plugin, but it didn't look like it plays very well with 2.2. Anyone > know of other plugins that might be useful? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Using a model in a library
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.is_a? Aircraft > ... > end > end > > I'm doing this in a library class (the file is in lib/) and I get an > uninitialized constant Aircraft error. Aircraft is a model class, with > a corresponding aircraft.rb file in app/models. > > Can I use model classes and instances in a library? How? > > Thanks, > Xtian --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Emailing: lots of recipients + individual mails/attachments
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: > > - mails to a lot of people ("mass" mailing) > - recipients can have 1 or more attachments (various formats) > - attachments are individual files (with individual file names) > - recipients get individual mails (100% individual content, not just > standard text with personalized greetings) > > I have found the following script, but it seems to be made for the case > where: > - everybody gets the exact same email > - emails have no attachments > > http://www.myowndb.com/blog/?p=20 > > Can you help me with this? > > Thanks a lot for any suggestions! > Tom > -- > Posted viahttp://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: How to wait and check for login to an external site
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 > able to save an event they selected to an online calendar such as Google > Calendar. I have a link to Google Calendar a user can click to open it > in a new tab once the user selected an event. I don't need to save user > email info so the best approach I think is to wait for the user to log > into the Google app and then my code adds the selected event into the > calendar. > > I guess I need to have a loop (with a timeout) in an action checking to > see if the user has logged in. My idea is to try to get the url of the > logged in page using Mechanize like this: page = > agent.get("https://www.google.com/calendar/render";). This is perhaps a > dumb idea. Or do I really need to capture the login event somehow. > > What should I do to accomplish this goal? What tool (gem) I should use > to do this? Please put me on the right track with some guidelines or > link to resources, thanks! > -- > Posted viahttp://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Named Route question
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 27, 7:29 pm, giorgio <[EMAIL PROTECTED]> wrote: > But what is the point of having the default routes if you cant get to > them? > > Is the idea to make a named route for everything? > > G --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Where to initialize session variables?
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_stuff return if session_stuff_is_already_set? end On Nov 27, 11:54 am, Jej <[EMAIL PROTECTED]> wrote: > Hi all, > > I would like to initialize some session variables when the user visits > the app for the first time. Currently I do it in an application > before_filter (escaped if the session already exists), but that occurs > for each request, it's dirty. > > Do you have any better solution? > > Jej --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: SQL in rails
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 me an example that use SQL in models to handel data in > the data base. with "sql.execute" or any other possible way.. > > thankx --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: How to easily cache single AR object?
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 == name @active_style = Style.find_by_name(name) return @active_style end end style = StylesCache.by_name("newsletter") On Oct 22, 4:36 pm, szimek <[EMAIL PROTECTED]> wrote: > Hi, > > I got a mailer that uses dynamic stylesheets, so when creating an > email I'm doing Style.find_by_name("newsletter"). > > The problem is that it's fetching the same Style record for each email > it creates and when sending newsletters there can be a lot of them. I > could simply fetch this record in controller and just pass it as a > parameter for deliver_email method, but it doesn't seem right for me - > I'd like to keep as much as possible inside mailer class. > > I can't also simply put STYLE = Style.find_by_name("newsletter") into > Mailer class, because if admin changes the style, the mailer would > still use cached object. > > Is there a *simple* way to do it? This Style object can only be > updated - it can't be destroyed. I'm using Rails 2.1.1. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: catch-all routing
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 is it possible to do > catch-all routing so that some value can be passed in as if it were a > controller for example > > http://localhost:3000/ford/thunderbirdhttp://localhost:3000/gm/solstice > > I know you can do it like this > > http://localhost:3000/manufacturers/ford/thunderbirdhttp://localhost:3000/manufacturers/gm/solstice > > but is it possible to skip the controller name? > > TIA. > > GP > -- > Posted viahttp://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: setting session id for first visit
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 an Event associated with that visitor for each request (this allows you to have multiple event_types). Then when doing your queries you can do visitor.events to see what each person did. This approach allows us to clean the session table out every few days so it doesnt get to slow. The visitor table only gets written to once for each person and then is read only going forward. On Oct 22, 10:51 am, gwgeller <[EMAIL PROTECTED]> wrote: > Kent, > I guess I really haven't thought it through, but my original > purpose was to group a visit using the session id as opposed to an ip > which could potentially be the same for two visitors. You mentioned > where I set the session id, but I don't do it, SqlSessionStore does it > for me, but I'm curious has to how that works. Do you know when the > session would be set? > > On Oct 22, 10:25 am, Kent Fenwick <[EMAIL PROTECTED]> > wrote: > > > It makes sense that the initial visit would not have a session id > > because depending on where you are assigning it, you might be logging > > the variable before setting it. > > > Also, you don't really need to hang on to the session details when > > logging web visits. Unless you have a special reason to, i wouldn't > > track any of the session details, they can easily be crated and > > compromised by scripts anyway. Try to keep session data to a minimum. > > > You might need to show some code if this doesn't help. > > > Kent > > > gwgeller wrote: > > > I am logging web visits with a before_filter on the application > > > controller. The issue I'm having is that the initial visit does not > > > return a session id. I'm using the SqlSessionStore and the function > > > MysqlSession.find_session(session.session_id) to retrieve the session > > > id. If it doesn't exist I use a -1. So looking in my visits table the > > > initial visit always has -1 for the session id and the rest of the > > > visits contain a valid session id for that visitor. > > > > I tried putting the logging of visits in the after filter but that > > > didn't seem to work. Is this something that I can correct or is that > > > just the way it is with sessions? > > > > Thanks, > > > Gunner > > > -- > > Posted viahttp://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Counting / Aggregation Queries
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 = ?", file.id] } } end Download.between("2008-10-01".to_date, "2008-11-01".to_date).from_file(file).count On Oct 21, 1:25 pm, Neal L <[EMAIL PROTECTED]> wrote: > Hi all, > > Suppose you have two models -- one for Files and anther for Downloads > -- such that a file has_many => :downloads > > If you wanted to get a count of the downloads for the current month > and the two previous months, is there a way to get that data from one > query? Something like: > > @file.downloads_for_month( 2008, 10 ) > > where 2008 is the year and 10 is the month... > > Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Convert Illustrator file to HTML or CSS for programming on Ruby?
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]> wrote: > > > Export it to Photoshop as a PSD, slice it up from there, then have > > your programmer clean up the output and add the dynamic content. > > > On Oct 17, 8:53 pm, carladeluxe <[EMAIL PROTECTED]> wrote: > > > HI there, > > > > My graphic designer and my programmer are having a communications > > > snafu, and it's my job to translate. > > > > The programmer is saying that if there's a simple conversion method to > > > take web page designs created in Illustrator and convert them to HTML > > > or CSS, it will save him about 50% of programming time. > > > > This is good news for everyone, but how best does the conversion > > > happen? > > > > Thanks for your consideration. > > > > Carla --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Running SQL file from inside rake task
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: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: ActionView: render a layout not in app/views?
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_ROOT/ app/ cms/ experiences/ 1/ layout.html.erb config/ ... Does that help? On Oct 14, 4:25 pm, Matthew Rudy Jacobs <[EMAIL PROTECTED] s.net> wrote: > Hey there, > I have a problem. > > class ApplicationController > layout :determine_layout > > def determine_layout > "../../public/[EMAIL PROTECTED]/application" > end > end > > in rails2.0 this worked, but it was clearly a hack. > > I tried to fix it in a few ways; > > 1. symlink public/sites -> app/views/layouts/sites > - this breaks because the Dir.glob used to find view files doesnt work > for subfolders of a symlink > > 2. set ApplicationController.view_paths << "public/sites" > - this doesnt quite seem to work. > > 3. manually fix rails and work out the best way to patch it for 2.2.1 > - this seemed to work, but isn't quite plugin-able as a fix > > mostly I'm wondering, > what is the right way to do this? > > MatthewRudy > -- > Posted viahttp://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Subdomains
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 recently? On Sep 24, 11:04 pm, Sav <[EMAIL PROTECTED]> wrote: > I've got a working app at mysite.com and trying to add > iphone.mysite.com - problem is that I get the classic "Application > error - Rails application failed to start properly" and I don't see > anything new in while tailing my log/development.log file. Any ideas > where else I can look or what could be wrong? > > Here is what is in my controllers/application.rb... > > before_filter :detect_request > > def detect_request > request.format = :iphone if iphone_request? > request.format = :mobi if mobile_request? > end > > def iphone_request? > request.subdomains.first == "iphone" > end > > def mobile_request? > request.subdomains.first == "m" > end --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Get Rid of Date in Migration Filename
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 was wondering how to get Rails 2.1 migrates to go from generating > 20080910014108_create_table.rb-esque migrations to the old > 22_create_table.rb style ones. I am sure that there is some sort of > advantage in having timestamps in the file name, I just haven't > figured it out yet. > > Thanks in advance, > > Joe --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Configuring custom library
Most of the Rails libraries use the following pattern: class Something @@config1 = "change_me" cattr_accessor :config1 end Something.config1 = "secret code" On Sep 7, 10:38 am, javinto <[EMAIL PROTECTED]> wrote: > Thanks!! > > You made me dive into this matter deep this time. I get the picture > now. That's partially then. As I'm still looking for a way to > configure things in a way, well like Rails does, e.g. in the > initializers: ActiveSupport.escape_html_entities_in_json = false > > But then, I don't know wether ActiveSupport 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 to mention is that if you do: > > > module AccountSystem > > class << self > > attr_accessor :account_system_type > > end > > end > > > You are actually putting the attr_accessor on the class Module, not on > > the class that AccountSystem will be included in. You need to use the > > included method, 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 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 > > > ApplicationController you must do something like this: > > > > Module AccountSystem > > > SINGLE = 1 > > > MULTIPLE = 2 > > > > self.included(klass) > > > klass.send(:cattr_accessor, :account_system_id) > > > end > > > end > > > > class ApplicationController < ActionController::Base > > > include AccountSystem > > > > # this is how you would use it > > > def random_method > > > self.class.account_system_id == AccountSystem::SINGLE > > > end > > > end > > > > That should do what you seem to want, but if your goal was something > > > different let me know and I can try to help. > > > > Of note, if you do use the above solution you could do: > > > > Module AccountSystem > > > ... > > > > def single? > > > self.class.account_system_id == SINGLE > > > end > > > > def multiple? > > > self.class.account_system_id == MULTIPLE > > > end > > > > ... > > > end > > > > class ApplicationController < ActionController::Base > > > include AccountSystem > > > > # this is how you would use it > > > def random_method > > > if single? > > > puts "single" > > > elsif multiple? > > > puts "multiple" > > > else > > > raise "please set the AccountSystem.acoun_type_id" > > > end > > > end > > > end > > > > On Sep 6, 12:08 pm, javinto <[EMAIL PROTECTED]> wrote: > > > > > Hi, > > > > > I've added a custom library called lib\AccountSystem like so: > > > > > "module AccountSystem > > > > SINGLE = 1 > > > > MULTIPLE = 2 > > > > > class << self > > > > attr_accessor :account_system_type > > > > end > > > > end" > > > > > Now I wanna configure > > > > AccountSystem.account_system_type=AccountSystem::SINGLE in one app. I > > > > used an initializer: config/initializers/account_initialization.rb > > > > where I put this line in. > > > > > I included my AccountSystem in the ApplicationController. > > > > > So now I'd like to check within my controllers the value of > > > > AccountSystem.account_system_type > > > > > But there it is empty! > > > > However if I run "Ruby script\console" and type > > > > AccountSystem.account_system_type I get the value of 1 as I would > > > > expect. > > > > > How can I achieve the same result within my controllers? > > > > > I'm on rails 2.1.0/2.1.1 > > > > > Thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Configuring custom library
What I forgot to mention is that if you do: module AccountSystem class << self attr_accessor :account_system_type end end You are actually putting the attr_accessor on the class Module, not on the class that AccountSystem will be included in. You need to use the included method, 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 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 > ApplicationController you must do something like this: > > Module AccountSystem > SINGLE = 1 > MULTIPLE = 2 > > self.included(klass) > klass.send(:cattr_accessor, :account_system_id) > end > end > > class ApplicationController < ActionController::Base > include AccountSystem > > # this is how you would use it > def random_method > self.class.account_system_id == AccountSystem::SINGLE > end > end > > That should do what you seem to want, but if your goal was something > different let me know and I can try to help. > > Of note, if you do use the above solution you could do: > > Module AccountSystem > ... > > def single? > self.class.account_system_id == SINGLE > end > > def multiple? > self.class.account_system_id == MULTIPLE > end > > ... > end > > class ApplicationController < ActionController::Base > include AccountSystem > > # this is how you would use it > def random_method > if single? > puts "single" > elsif multiple? > puts "multiple" > else > raise "please set the AccountSystem.acoun_type_id" > end > end > end > > On Sep 6, 12:08 pm, javinto <[EMAIL PROTECTED]> wrote: > > > Hi, > > > I've added a custom library called lib\AccountSystem like so: > > > "module AccountSystem > > SINGLE = 1 > > MULTIPLE = 2 > > > class << self > > attr_accessor :account_system_type > > end > > end" > > > Now I wanna configure > > AccountSystem.account_system_type=AccountSystem::SINGLE in one app. I > > used an initializer: config/initializers/account_initialization.rb > > where I put this line in. > > > I included my AccountSystem in the ApplicationController. > > > So now I'd like to check within my controllers the value of > > AccountSystem.account_system_type > > > But there it is empty! > > However if I run "Ruby script\console" and type > > AccountSystem.account_system_type I get the value of 1 as I would > > expect. > > > How can I achieve the same result within my controllers? > > > I'm on rails 2.1.0/2.1.1 > > > Thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Web administration interface for Rails?!
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 typus. What's > better? > > Thank your for you attention! > > -- > Regards, > > Luiz Vitor Martinez Cardoso > cel.: (11) 8187-8662 > blog: rubz.org > engineer student at maua.br > > "Posso nunca chegar a ser o melhor engenheiro do mundo, mas tenha certeza de > que eu vou lutar com todas as minhas forças para ser o melhor engenheiro que > eu puder ser" --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Configuring custom library
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 ApplicationController you must do something like this: Module AccountSystem SINGLE = 1 MULTIPLE = 2 self.included(klass) klass.send(:cattr_accessor, :account_system_id) end end class ApplicationController < ActionController::Base include AccountSystem # this is how you would use it def random_method self.class.account_system_id == AccountSystem::SINGLE end end That should do what you seem to want, but if your goal was something different let me know and I can try to help. Of note, if you do use the above solution you could do: Module AccountSystem ... def single? self.class.account_system_id == SINGLE end def multiple? self.class.account_system_id == MULTIPLE end ... end class ApplicationController < ActionController::Base include AccountSystem # this is how you would use it def random_method if single? puts "single" elsif multiple? puts "multiple" else raise "please set the AccountSystem.acoun_type_id" end end end On Sep 6, 12:08 pm, javinto <[EMAIL PROTECTED]> wrote: > Hi, > > I've added a custom library called lib\AccountSystem like so: > > "module AccountSystem > SINGLE = 1 > MULTIPLE = 2 > > class << self > attr_accessor :account_system_type > end > end" > > Now I wanna configure > AccountSystem.account_system_type=AccountSystem::SINGLE in one app. I > used an initializer: config/initializers/account_initialization.rb > where I put this line in. > > I included my AccountSystem in the ApplicationController. > > So now I'd like to check within my controllers the value of > AccountSystem.account_system_type > > But there it is empty! > However if I run "Ruby script\console" and type > AccountSystem.account_system_type I get the value of 1 as I would > expect. > > How can I achieve the same result within my controllers? > > I'm on rails 2.1.0/2.1.1 > > Thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---