search for: sort_by

Displaying 20 results from an estimated 83 matches for "sort_by".

2006 Dec 04
10
Avoiding SQL Injection in :order?
...the format > :conditions => [ "user_name = ?", user_name] Is there any such system for escaping injection in :order? It seems to only take a string and feed it to the SQL statement. This causes a vulnerability when using params to set :order as in this function: def list sort_by = params[:sort_by] @book_pages, @books = paginate :books, :order => sort_by, :per_page => 10 end We''ve tried a few methods to sanitize sort_by such as :order => [''?'', sort_by] but it jus...
2006 Jul 20
3
sort_by with via a parent models child
I am having a problem with ruby''s sort_by function. I want to sort a list of parent model objects based on the children of the parent models. Normally you might say sortedList = modelList.sort_by { |model| model[''someAttribute''] } What I am tring to do is sortedList = modelList.sort_by{ |model| model.children.find(:fi...
2007 Sep 05
4
Mocking to spec a sort_by method
Hello, I have a question regarding the use of Mocha with rSpec to spec one of my methods. My spec contains the following vehical1 = mock() vehical2 = mock() vehical1.stubs(:mph).returns(150) vehical2.stubs(:mph).returns(250) comparer.add_vehical([@vehical1, @vehical2]) comparer.sort_by(:mph) The comparer is an object that has a basic "stack like" functionality, add_vehical is the method to add objects to the stack. My sort_by method in the comparer class looks like def sort_by(symb) @vehicals.sort_by{|vehical| vehical[symb] } end where @vehicals is an instance v...
2006 Feb 08
7
DRY methodology
because I am a grasshopper... Now that I can sort my ''list''...is there a logical way of not repeating myself to having essentially the same list view with multiple sorts? i.e. def list_cl # ordered by clients last name @placement_pages, @placements = paginate( :placements, :include => [:client], :order_by =>
2006 May 14
4
searching on foreing keys
...another table people(id,name) owner_id being a foreign key of pet pointing to people name. here it is on the pet controller: @paginator, @pets= paginate(:pets, :conditions =>["name OR owner_id like ?","%"+params[:filter]+"%"], :include =>person,:order_by => @sort_by,:per_page => default_per_page ) it searches great in name but not in owner_id. I mean it searches through people id instead of the person name it''s referring. Any idea how to make it search through the foreign key? thanx in advance Pat
2012 Mar 28
4
Hash iteration order in a template not consistent
...values in the order that the corresponding keys were inserted.", but is that not true for Puppet hashes? I did stumble across this post: http://serverfault.com/questions/368784/puppet-and-templates-how-to-loop-sequently-and-not-randomly which suggests to do something like <% aliases.sort_by {|key, value| key}.each_pair do |key, val| -%> <% end -%> Will it work? Is that a proper solution? Thanks! Martijn Grendelman -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-use...
2007 Jan 25
2
React on select_tag (onchange)
Hi, I''m new in developint rails (but I love rails). I would like to react on changing a field in the view (no model field) from a selection box to show the number of rows (which I used in the controller). In the controller I read the params-hash: ... @rowsperpage = params[''rowsperpage''].to_i ... In the view I have the field, where I like to react directly. ...
2012 Sep 10
3
How to remove last comma when iterating through hash in erb template
...uot;ip1,ip2,ip3" I am using the method below to sort the hash before iterating over it. However, as you can see there will always be a final comma which breaks the app that uses this config file. Does anyone know how I could remove the final comma? ipv4_bind_addresses = "<% routes.sort_by {|key, v| key}.each do |key, v| -%><%= net %>.<%= v[''pubnet''] %>.1,<% end -%>" -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.c...
2009 Jan 13
1
ROR - Excel Export Example
If you are running on Windows you can use create and read speadsheets using the ''win32ole'' require This sample should give you the basic idea ------ def export require ''win32ole'' @sort_by = ''last_name'' current_user = ''steve'' @records = Contact.find( :all, :conditions => ["created_by = ?", self.current_user.login.to_s] #, #:order => @sort_by ) # Creates OLE object to Excel...
2006 Jan 10
1
sql server freetds/odbc question
...ie ------ class ActionController::Base def paginate_with_sort(collection_id, options={}) @params[:sort_direction] ||= ''-1'' asc_desc = {''1'' => "asc", ''-1'' => "desc"} options[:order] = "#{@params[:sort_by]} #{asc_desc[@params [:sort_direction]]}" if @params[:sort_by] @params[:sort_direction] = @params[:sort_direction].to_i * (-1) paginate collection_id, options end end
2006 Mar 29
4
Directory Listing outside of app structure
I need to show a directory listing of a folder outside of the Rails app structure. Moving the folder is not an option. In fact, changing anything (including modes) is not possible for the folder. I have working directory listing code in Ruby, but if I call chdir in Rails to set the working directory to a folder outside the app tree, nothing is returned to the browser. It''s fine if I
2006 Apr 03
2
Order By Number of Comments
Hi, I am new to Ruby on Rails, so I apologise if this has been answered elsewhere. I have had a look through the list but I can''t seem to find what I am trying to do. I have implemented the standard blog and comments app from the screencast. However I am trying to extend the functionality. I want to be able to display a list of posts and order them by the total number of comments
2008 Mar 28
6
Eager Loading + Confusion
...es thing, but some of the columns are attributes through associations. So I did some eager loading with the :include option to try and access the attributes of the object I''m doing the find on. Stuff has been blowing up on me so far. Here''s the code in the controller right now: sort_by = params[:sort_by] || ''id'' direction = params[:direction] || ''desc'' @state_agency_grants = Grant.paginate(:all, :include => [:funding_entity, :creator_entity, applying_entity], :order=> "#{sort_by} #{direction}" ,:page => params[:page], :per_p...
2006 Jan 10
1
sql server & linux: left join problem
...----------- class ActionController::Base def paginate_with_sort(collection_id, options={}) @params[:sort_direction] ||= ''-1'' asc_desc = {''1'' => "asc", ''-1'' => "desc"} options[:order] = "#{@params[:sort_by]} #{asc_desc[@params [:sort_direction]]}" if @params[:sort_by] @params[:sort_direction] = @params[:sort_direction].to_i * (-1) paginate collection_id, options end end
2018 Jan 19
1
Web scraping different levels of a website
...log.ihsn.org/index.php/catalog/", "search?view=s&", "ps={num_studies}&", "page=1&repo=&repo_ref=&sid=&_r=&sk=&vk=&", "from={year_from}&", "to={year_to}&", "sort_order=&sort_by=nation&_=1516371984886") # read in the html x <- url %>% GET() %>% content() # option 1 (div with class "survey-row" --> data-url attribute) x %>% html_nodes(".survey-row") %>% html_attr("data-url") # option 2 (studies titles are...
2018 Jan 18
0
Web scraping different levels of a website
I am web scraping a page at http://catalog.ihsn.org/index.php/catalog#_r=&collection=&country=&dtype=&from=1890&page=1&ps=100&sid=&sk=&sort_by=nation&sort_order=&to=2017&topic=&view=s&vk= From this url, I have built up a dataframe through the following code: dflist <- map(.x = 1:417, .f = function(x) { Sys.sleep(5) url <- ("http://catalog.ihsn.org/index.php/catalog#_r=&collection=&country=&dt...
2006 Mar 22
2
has_many, belongs_to
I have one table(profiles) where each row has many rows in another table(carriers). If I write profile.carriers I get a collection containing all carriers that belong to the current profile. My question is: how do I sort the collection profile.carriers? I would like to sort it on one of the columns (found in the table carriers). Can I override some method in the carrier model or somewhere
2006 May 02
4
ordering after a inject
...t;=>1, " baseball"=>2} I can''t figure out why or how to correct it. I don''t have the latest pickaxe book which documents the inject function and can''t find much documentation on it on the web. I could turn it into an sorted array using "count = count.sort_by { |r| r.name }", but I don''t want it in an array. In need it in a hash. Any ideas? Kind regards, Steve Odom http://www.smarkets.net -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060502/d5d3...
2006 Feb 19
2
progressive updates
...with is passing the selection from my pop-up list to the link_to tag. <%= options = [[params[:vw], ""]] + Placement::VW_STRING select("", :vw, options) %> <%= link_to ''Update'', :action => ''list'', :vw => params[:vw], :sort_by => params[:sort_by] %> My problem is that what I select from the list doesn''t change the value :vw in the ''link_to'' How does one do this sort of thing? Craig
2006 Jul 25
4
Sorting by two fields
I have a list of TimeSheet objects from an ealier AR query, which I can sort by the full name of the user like so: @time_sheet_entries.sort! { |a,b| a.user.full_name <=> b.user.full_name } I can sort by the started time like so: @time_sheet_entries.sort! { |a,b| a.start_time <=> b.start_time } My question is how do I do a sort so that the list is sorted primarily by user.full_name