This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| documents = Document.find :all | |
| format.xml{render :xml=>documents.to_xml(:include=>{:person=>{:only=>[:surname, :age]}, //how to rename the attribute "surname" to "name"? | |
| :only=>:nr)} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template = 'people' # depends on the template | |
| ... | |
| @nested_object = self.instance_variable_get(:"@#{params[:controller].singularize}") if show_action? | |
| ... | |
| attributes.each do |attribute| | |
| route = @nested_object ? self.send("#{params[:controller].singularize}_#{template}_path", @nested_object, {:order=>order}) : self.send("#{params[:controller]}_path", {:order=>order}) | |
| link_to('Fooo', route) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # towns_controller.rb | |
| def show | |
| @town = Town.find_by_id params[:id], :include=>:town | |
| if_object @town do | |
| @result_list = result_list_of :person, 'middle_age' | |
| @nested_resource = :town | |
| @people = Person.paginate :per_page=>@result_list.items_per_page, | |
| :page=>@result_list.page, | |
| :include=>Person.reflections.keys, | |
| :order=>Person.sort_clause(@result_list.attribute_result_list), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <%form_for(@main_group, :url=>main_group_path(@main_group), :html=>{:id=>"form_panel"}) do |form|%> | |
| <%=form.select(:group_ids, @groups.collect{|g| [g.code, g.id]}, {}, | |
| {:size=>4, :multiple=>true, :id=>'source_baugruppe_ids'})%> | |
| <%=form.submit '>>', {:class=>'btn_shift_right'}%> | |
| <%=form.submit '<<', {:class=>'btn_shift_left'}%> | |
| <%=form.select(:group_ids, @main_group.groups.collect{|g| [g.code, g.id]}, {}, {:size=>4, :multiple=>true, :class=>'destination'})%> | |
| <%-end-%> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| people_controller.rb: | |
| class PeopleController < ApplicationController | |
| end | |
| the PeopleController shall handle all people (asia, europe, america, africa, australia): | |
| but i'd like to have routes like: | |
| - /asia/12 -> PeopleController.show params=>{:id=>12, :continent=>'asia'} :get | |
| - /america -> PeopleController.index params=>{:continent=>'america'} :get | |
| - /africa/3/edit -> PeopleController.edit params=>{:id=>3, :continent=>'africa'} :get |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| map.people '/:person', :controller=>:people, | |
| :requirements=>{:person=>/(asian|european|american|african|australian)/} | |
| i expected: people_path(:person=>'asian') to create /asian but it creates /people?person=asian |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| map.with_options :controller=>'people' do |people| | |
| people.people '/:continent', :action=>"index", :conditions=>{:method=>'get'}, | |
| :requirements=>{:continent=>/(asia|europe|america|africa|australia)/} | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def destroy | |
| callback(:before_destroy) | |
| update_attribute_with_validation_skipping :inaktiv, true # i'd like to skip the after_update callback raised by update_attribute_with_validation_skipping | |
| freeze | |
| callback(:after_destroy) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Form-model form.rb: | |
| before_destroy :validate_assoc | |
| def validate_assoc | |
| if inactive && !(towers = Tower.find(:all, :conditions=>{:form_id=>id})).blank? | |
| towers.each{|tower| errors.add(:inactive, tower )} | |
| false | |
| end | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| string = File.open('my_file.csv'){|f| f.read} | |
| p string | |
| string.split("\n").each do |row| | |
| row.strip.split("|").each do |col| | |
| p(col) | |
| end | |
| end |
OlderNewer