Displaying 20 results from an estimated 2000 matches similar to: "DRY DRY DRY"
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 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
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
2005 Dec 29
0
strange output in http header
Hi there,
I''m experiencing something strange in rails http headers. The response
comes back as text/plain. The http header looks like this:
HTTP/1.1 200 OK
Date: Thu, 29 Dec 2005 15:18:18 GMT
Server: Apache/2.0.54 (Debian GNU/Linux) PHP/4.3.10-16 mod_ruby/1.2.4
Ruby/1.8.4(2005-10-29)
#<#<Class: 0x40a7f818>:0x40a7f778>Content-Type: text/html
Cache-Control: no-cache
2007 Jun 20
1
Count_by_content ??
Is there a count_by_content alternative to the find_by_content action?
This is because I''m wanting to do the following in my pagination method:
def list
# step 1: set the variables you''ll need
page = (params[:page] ||= 1).to_i
items_per_page = 20
offset = (page - 1) * items_per_page
# step 2: instead of performing a find, just get a count
item_count =
2007 May 12
3
Setting form-values
Hi,
I''ve recently had some trouble setting form values in my code - for example:
require ''rubygems''
require ''mechanize''
def save(pagename, content, editsummary = '''')
agent = WWW::Mechanize.new
agent.user_agent = ''Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)''
page =
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
2008 Apr 26
0
moving pagination code to model
Hi
I have the controller code as below
# step 1: set the variables you''ll need
page = (params[:page] ||= 1).to_i
items_per_page = 20
offset = (page - 1) * items_per_page
# step 2: instead of performing the full find, just find the
record count
@search_sd_ticket_count_result =
2008 May 19
0
changed to will_paginate
Hi
Till now we used the rails pagination.But now onwards shifting to
will_paginate
The code I use currently is as below .This is with the help of
find_where pluggin..A fantastic pluggin which we still want to use...I
would like to know how can i modify the following code to work with
will_paginate
step 1: set the variables you''ll need
page = (params[:page] ||= 1).to_i
2008 Mar 06
1
pagination for an object array
def show_details
@sd_ticket = ServiceDeskTicket.find(params[:id])
@servicedesk_cis = @sd_ticket.service_desk_cis
end
What I need is a pagination for @servicedesk_cis using the custom
pagination..How can i give offset and limit to this?
I have successfully done previously custom pagination in another def as
below
def search_sd_ticket
@search_sd_ui_hash=params[:sd_ticket]
2006 Oct 02
6
Strange Sorting Issues
Hi there,
I''m having some strange sorting stuff goign on. Here''s my search method:
sort_fields = []
sort_fields << Ferret::Search::SortField.new("name",
:reverse => :false)
@results = Listing.find_by_contents @search_criteria, :limit => :all,
:sort => sort_fields
page = (params[:page] ||= 1).to_i
items_per_page = 9
offset = (page - 1) *
2006 Oct 11
2
Mechanize: save and cancel doesn''t work in JSPWiki
I''m trying to submit data in JSPWiki (edit page). I can read the data
in the form, but nothings get saved when I submit the page. Cancel
doesn''t work either. I don''t get any errors. There is no JavaScript
used to submit the form.
After I''m logged in I do the following:
def save(page, content)
@agent.get(@base_url + "Edit.jsp?page=#{page}")
2006 Jun 17
0
Dynamic forms containing collections
Hiall,
I have the following problem: I need to use forms containing
collections (i will call them FCC), and I want to construct them
dynamically, as I need to deal with quite large forms (more than 600
input fields).
The variables @model_name and @field_name contain the proper model and
field names as strings, which is enough for "normal" form input
fields. (i.e. the "if
2011 Jul 11
2
Can't get this Rspec test to pass
Hello,
I''m completely new to Rspec testing and I''m finding it very difficult to
mock specific objects.
In this test, I have a before block setup as such:
[code]
before do
setup_controller_for_warden
controller.session[:operation_id] = 1
@operator = Factory :operator
sign_in :operator, @operator
@persist_herd = Herd.new
2010 Oct 11
5
Object lost in memory/trashed?
Hi,
I''ve got a problem on which I''ve spent many hours, and I can''t get a
clue on what is happening... I hope someone here will be able to help
me.
Here is the situation : my Rails app uses acts_as_commentable and
acts_as_bookmarkable on a Diagram model. Everything''s working OK
individually: I can create a comment on a Diagram, bookmark it, and so
on.
Now,
2006 Jun 18
2
using javascript to get an attribute using an ID
Hi everyone,
I''m trying to use ajax to update the selected value of a select element.
Here''s what I have so far:
function RailsModel(model_name)
{
this.model_name = model_name;
}
RailsModel.prototype.getAttributeById = function(attribute, id)
{
Ajax.Request(''/models/get_attribute_by_id/'' + this.model_name + ''/'' +
attribute +
2006 Jan 13
1
association callbacks
Hello all. I am looking for some feedback on an implementation. I''m writing
a plugin that will log all model changes. I do not want to have to add a
line a code for this functionality every time I create a model. Instead I
create a table with the name <model>_changes.
The basic stuff was easy:
base.after_create {|model|
model.log_create if model.has_backup_table?
2006 Feb 20
2
file_column: changing default store_dir
File_column plugin is great. I need to change the default :store_dir
from the dynamic "model_name/attribute_name" to an equally dynamic
"client_id/app_id/model_name/attribute_name". In my model I have:
class Component < ActiveRecord::Base
belongs_to :component_type
belongs_to :component_group
breakpoint
file_column :content,
:magick => { :versions
2006 Jun 26
2
DRY up selects in view
Here''s what I''ve got:
<% @fields.each do |field_name| %>
<tr>
<td>
<%= field_name.humanize %>
</td>
<td>
<% unless field_name =~ /_id$/ %>
<%= form.text_field field_name, :size => 40 %>
<% else %>
<%= select(:vendor,
field_name,
State.find(:all, :order
2007 Mar 19
0
action_web_services error with rspec_on_rails
I now have two specs in my rails project which correspond to one
rails controller. I can run them individually and they pass, but
running them together (either with the rake task just putting both
files on the command line):
euclid% spec spec/controllers/crud_resource_controller_spec.rb spec/
controllers/crud_resource_controller_with_join_models_spec.rb