search for: model_class

Displaying 12 results from an estimated 12 matches for "model_class".

2012 Apr 25
2
Rails 3.1 - Scaffolding Files
Where can I find more information about the new syntax on these: <%- model_class = @product.class -%> <h1><%=t ''.title'', :default => t(''helpers.titles.new'', :model => model_class.model_name.human, :default => "New #{model_class.model_name.human}") %></h1> <%= render :...
2006 Aug 04
4
DRY DRY DRY
...... class BasicCRUDController < ApplicationController ITEMS_PER_PAGE = 15 before_filter :initialize_crud_controller verify :method => :post, :only => [ :destroy, :create, :update ], :redirect_to => { :action => :list } def index list end def list @items = model_class.find :all, :limit => ITEMS_PER_PAGE, :offset => ITEMS_PER_PAGE * (@sess[:page] - 1) @pages = Paginator.new self, model_class.count, ITEMS_PER_PAGE, @sess[:page] render ''shared/list'' end def new @item = model_class.new #@editf...
2006 Jun 08
3
Macros and stuff
...controller code and the edit/create/update/new for each are practically identical. So first I DRY''d the four methods in each controller to just one and then I decided to write a single macro for all my controllers. This is the macro: def self.edit_action_for(model, options = {}) model_class = Object.const_get(model) define_method(:edit) do edit_code = lambda do @thing = model_class.find_by_id(params[:id]) || model_class.new if request.post? @thing.attributes = params[:impactable_area] if @thing.save flash[:notice] = "#{mod...
2009 Apr 19
19
Controller spec: testing that scope is set
In a Rails controller I set the scope on a model class in an around filter. I have defined expectations on the model classes, and ideally, I would add a further expectation for the scope. Is this already possible in some way? How would I go about adding support a scope expectation? Michael -- Michael Schuerig mailto:michael at schuerig.de http://www.schuerig.de/michael/
2006 Apr 18
4
how would you take the duplication out of this?
i have these two really similar methods in my addressbook controller. def edit_company @company = Company.find(params[:id]) if request.post? and @company.update_attributes(params[:company]) flash[:notice] = ''Company was successfully edited.'' redirect_to :action => ''show'', :id => @company end end def edit_person
2007 Mar 29
21
a better "should have valid associations"
...moved some associations. And it won''t check for polymorphs either.) Put this somewhere handy and require it into spec_helper. ======================================== module ActiveRecordMatchers class HaveValidAssociations def matches?(model) @failed_association = nil @model_class = model.class model.class.reflect_on_all_associations.each do |assoc| begin model.send(assoc.name, true) model.class.send(''find'', :first, :include => assoc.name) rescue ActiveRecord::EagerLoadPolymorphicError # nothing. Can...
2010 Oct 11
5
Object lost in memory/trashed?
...t;show" view of a diagram, which shows all comments and a line per bookmark saying something like "John added this diagram as a favorite". I''ve got an action in a comments controller fetching the data: # Get bookmarked class from params and fetch the wanted instance model_class = Kernel.const_get(params[:commentable][:type].capitalize) instance = model_class.find params[:commentable][:id] report_error("Cannot find " << model_class.to_s << " with id " << params[:commentable][:id].to_s) if instance.nil? @comments = instance....
2008 May 28
3
Plug-in support for Camping Apps
# camping_plugin.rb # plug-in support for Camping Apps # require ''lib/camping_plugin'' # override R helper method to your liking :-) module Camping module PluginHelpers def R_with_module(c,*g) p,h=/\(.+?\)/,g.grep(Hash) g-=h raise "bad route" unless u = c.urls.find{|x| break x if x.scan(p).size == g.size &&
2006 Feb 17
3
Ajax On Rails
Hi, I want database query in rail for ''LIKE'' i.e in sql it something like. "SELECT * FROM tablename where filedname LIKE ''%keyword%'' " etc. What for rail? -- Posted via http://www.ruby-forum.com/.
2009 Feb 07
0
wice grid
...hing displays on the page. when i look at page source -- there is on <th></th> here is the view: <%= grid(@installed_softwares) do |g| g.column :column_name =>''Software:'', :attribute_name => ''name'', :no_filter => true, :model_class => Software do |isoftware| isoftware.software.name end g.column do |isoftware| link_to "Show", hardware_installed_softwares_path (:hardware_id,isoftware) end end %> here is controller view: class InstalledSoftwaresController < ApplicationController def index #...
2007 Mar 21
2
store_class_name for Comatose:Page model
Hi, I have three models: Comatose::Page, Article and Product. In all of them, store_class_name is set to true. Now, when i do: results = Comatose::Page.multi_search("*", [Article,Product], options) I get: wrong constant name Comatose::Page #{RAILS_ROOT}/vendor/plugins/acts_as_ferret/lib/class_methods.rb:438:in `const_get''
2007 Oct 21
13
[ANN/RFC] Rathole, a fixtures extension plugin
Like lots of other folks, I''ve been searching for a way to scratch my fixture itches. Rathole is my extraction of a few techniques we''ve successfully applied at my day job. We''ve been using Rathole for a month or so now, but I''d really like some feedback from a wider audience. Rathole tackles: * Conflicting PK''s (no more id''s in fixture