similar to: how would you take the duplication out of this?

Displaying 20 results from an estimated 500 matches similar to: "how would you take the duplication out of this?"

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 :partial =>
2006 Apr 20
5
strange mysql problem
i have this model: class LineItem < ActiveRecord::Base belongs_to :quote end in the console: >>l = LineItem.create ActiveRecord::StatementInvalid: Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' , , , )'' at line 1: INSERT INTO line_items (`qty`, `quote_id`,
2006 Apr 22
7
Instance variables versus local variables
This novice coder roughly understands the difference between instance and local variables thanks to David Black''s excellent book, but I''m still unclear as to when and why a either is more desirable to use. In general, I use instance variables in my controller and local in my views, but I''m not sure as to why or if this is correct. Thanks Joe Kowalski
2006 Jan 02
2
Dynamic form tags
Hi all, I''m happily using "HowToReuseEditViewsForNewViews" found at: http://wiki.rubyonrails.com/rails/pages/HowToReuseEditViewsForNewViews There''s this comment there saying you only need the tag "<%= auto_form %>" when using the code below. Can somebody tell me if that will work when extending it with model_name (some how)? I have several new_*
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 Jun 08
3
Macros and stuff
I was looking at my 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
2006 Aug 04
4
DRY DRY DRY
Hello everyone! Ive been on rails for the last month or so and really enjoyed this framework. However its very hard to find documentation on how to do things right! For example every beginner after a while realizes that having similar CRUD actions in every controller and views for them is not DRY at all! Few days ago I found http://dereksivers.com/rails-shared-controller.html I quite like his
2006 Jan 19
1
partials and instance variables for file_column
Hi, Sebastian Kanthak of the file_column-Plugin wrote once: "is the photo object inside a local variable or an instance variable (e.g. photo or @photo)? url_for_file_column only works with instance variables, like all other active record form helpers. Could this be the problem?" So I''m using file_column in a partial, e.g. <%= render (:partial => "product",
2007 Mar 29
21
a better "should have valid associations"
This is pretty much the same as last time around, if you recall. Thanks to Wilson for converting to the new form. I''ve added a few lines. Basically, it iterates over your model associations and does two things. - First, just try to call the association. Usually fixes speeling erors or other such silliness. - Second, try to find a record with an :include on the association. This
2007 Apr 01
12
How to List Records in Descending Order?
I am brand-new to RoR and have only followed and replicated the few tutorials that are out there. I have searched and searched, but cannot find an answer to this simple question: How can you list records in descending order? I have the cookbook example loaded, but can''t seem to list the recipes in reverse order (by the primary key - id). Thanks ahead of time for any and all help. --
2010 May 10
7
NilClass passed to partial view
Hi, I have a simple program that tries to do something really basic. First, I have a company Model : ------------------------------------- class Company < ActiveRecord::Base has_one :billingAddress, :foreign_key=>"id", :class_name=>"Address" end Then I have the address Model : -------------------------------------- class Address< ActiveRecord::Base belongs_to
2006 Mar 23
6
easy scaffold question(s)
I''m doing very well with the Hibbs Rolling on Rails tutorial. I have an easy question for my personal notes. I''m coming up with a simple framework of steps for creating a basic database. It includes the following maxims to make original app creation easy: app_name = MySQL database name SQL_tablename = model_name model_name = controller-name Is this going to work for getting
2006 Jan 04
4
file_column
I use file_column and it works fine. I tried to change the store_dir to a the path I want my files to be stored and not the default. I stored some images fine. But when I try to reach my images it seems like file_column uses the model_name/attribute_name on the image and not the store_dir I used. How can I change this ? Thanks in advance -- Alexander Antonakakis
2010 Apr 02
7
Liebert GXT2 NUT driver
Hi guys, I found the troblue and fix it! I attached the patch. The trouble was in the command reply buffer use. You compute the value that value = reply[6]*256+reply[5] <- it's wrong The right solution: value = reply[5] * 256 + reply[6]; And other bug, battery.runtime compute, you divide this value 60 <- it's wrong right value: divide 1.0 I continue the work on this
2006 Apr 27
3
collection_select to display 2 fields
I''m trying to get a collection_select generated Drop-down box to display two fields from a table (first name & last name); however, I am having trouble concatenating the symbols. It appears as though any code I put in the 5th argument for collection_select is processed prior to executing the collection_select method. The code executes successfully with 1 symbol in the 5th
2006 Jul 06
3
Accessing form field contents
I have an HTML form on the screen, that is connected to a database (standard Ruby way). I found that there are people that would rather not fill in this information, but would rather search Amazon for the info. Therefore, I added a link to the right of one of the fields that, when pressed, will search Amazon for what ever you typed into that field. So, how can I do that? At first I tried
2006 Jan 16
6
file_column plugin error
Hi, I downloaded FileColumn plugin and love the concept. But when I tried the example listed on the plugin web site, I got the following error: NoMethodError in Entry#new undefined method `file_column'' for Entry:Class My environement is Red Hat linux 9.0 with mysql 4.1. I installed file_column under vendor/plugins. If I run "ls", I get the following directories:
2006 Jun 26
8
id of last element in a table
Hi, I would like to figure out how to determine what the id of the last element in a table is. Is there an equivalent to the Table.find() method which will tell me the number of elements in a table? also, maybe more importantly, where are the available methods on tables documented? What i am trying to do is to increment the id and work through a table and check whether the id i am currently
2008 May 30
9
find_by_sql without a model? how to do this?
Hi, I''d like to do a "find_by_sql" without a model (e.g. <model name>.find_by_sql("...")) as the results I get back are a once off special, and I''m happy to handle them as an array. How do I do this? "ActiveRecord::Base.find_by_sql(...)" does not seem to work? Background - At the moment I''m doing within a model <model_name>,
2011 Jan 26
13
undefined method `model_name' for NilClass:Class
I am new to Ruby on Rails and have a very simple foreign key example that is driving me nuts. I am using Rails 3 under Windows Vista and have two tables: users and user_comments. user_comments.user_id should point to the user a comment is about. In my show view for user I have a link to the new method of user_comments to allow a comment to be created. This throws: Showing