Notes posted by mihserf
RSS feed![Default_avatar_30](https://www.gravatar.com/avatar/6884e669112d316ceb2fb862d0c8f474?default=http://apidock.com/images/default_avatar_30.png&size=30)
0 thanks
Grouping
Person.sum(:age, :group => “sex”) # =>[[“male”,2500],[“female”,2200]]
![Default_avatar_30](https://www.gravatar.com/avatar/6884e669112d316ceb2fb862d0c8f474?default=http://apidock.com/images/default_avatar_30.png&size=30)
2 thanks
Grouping
Person.sum(:age, :group => “sex”) # =>[[“male”,2500],[“female”,2200]]
![Default_avatar_30](https://www.gravatar.com/avatar/6884e669112d316ceb2fb862d0c8f474?default=http://apidock.com/images/default_avatar_30.png&size=30)
0 thanks
word_wrap with breaking long words
Code
def breaking_word_wrap(text, *args) options = args.extract_options! unless args.blank? options[:line_width] = args[0] || 80 end options.reverse_merge!(:line_width => 80) text = text.split(" ").collect do |word| word.length > options[:line_width] ? word.gsub(/(.{1,#{options[:line_width]}})/, "\\1 ") : word end * " " text.split("\n").collect do |line| line.length > options[:line_width] ? line.gsub(/(.{1,#{options[:line_width]}})(\s+|$)/, "\\1\n").strip : line end * "\n" end breaking_word_wrap("Once upon a supercalifragilisticexpialidocious time",15) # => Once upon a\nsupercalifragil\nisticexpialidoc\nious time
![Default_avatar_30](https://www.gravatar.com/avatar/6884e669112d316ceb2fb862d0c8f474?default=http://apidock.com/images/default_avatar_30.png&size=30)
1 thank
style for select
<%= select(“post”, “person_id”, Person.all.collect {|p| [ p.name, p.id ] }, {}, :style => “width:100px” %>
![Default_avatar_30](https://www.gravatar.com/avatar/6884e669112d316ceb2fb862d0c8f474?default=http://apidock.com/images/default_avatar_30.png&size=30)
1 thank
collection update
in the FirmsController
@firm.people.update(params[:people].keys,params.values)
in the View
<% form_for(@firm) do |f| %>
<%= f.error_messages %> <%= f.text_field :name %> <%@firm.people.each do |person|%> <%fields_for "people[]", person do |pf|%> <%= pf.text_field :name %> <%end%> <%= f.submit "Save" %>
<%end%>
![Default_avatar_30](https://www.gravatar.com/avatar/6884e669112d316ceb2fb862d0c8f474?default=http://apidock.com/images/default_avatar_30.png&size=30)
2 thanks
collection update
in the FirmsController
@firm.people.update(params[:people].keys,params.values)
in the View
<% form_for(@firm) do |f| %>
<%= f.error_messages %> <%= f.text_field :name %> <%@firm.people.each do |person|%> <%fields_for "people[]", person do |pf|%> <%= pf.text_field :name %> <%end%> <%= f.submit "Save" %>
<%end%>
![Default_avatar_30](https://www.gravatar.com/avatar/6884e669112d316ceb2fb862d0c8f474?default=http://apidock.com/images/default_avatar_30.png&size=30)
4 thanks
:conditions examples
:conditions => {:login => login, :password => password}
:conditions => [‘subject LIKE :foo OR body LIKE :foo’, {:foo => ‘woah’}]
(from the book “The Rails Way”)