Re: [Rails] Carrierwave metadata for original creation date?

2019-09-25 Thread Rob Biedenharn


> On 2019-Sep-25, at 14:45 , fugee ohu  wrote:
> 
> 
> 
> On Friday, September 20, 2019 at 5:13:44 PM UTC-4, Colin Law wrote:
> On Fri, 20 Sep 2019 at 18:10, fugee ohu > wrote: 
> > 
> > How do I keep a record of the original creation date? What if I wanna 
> > preserve the original creation date? 
> od 
> Each record in the database has a created_at field.  At least mine do. 
> 
> Colin 
> 
> I want the creation date of file before it's uploaded Can you tell me how to 
> find it I know it has something to do with ruby mtime function

You can't get that information in the browser. The best you could do is the 
lastModified 
 time of 
the file.


https://developer.mozilla.org/en-US/docs/Web/API/File 

https://developer.mozilla.org/en-US/docs/Web/API/File/lastModified 



-Rob

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/68360982-1BA8-45C7-A68B-EB2B4D2D8D89%40gmail.com.


Re: [Rails] How do I group and order by a model without loosing includes() method benefits

2019-06-06 Thread Rob Biedenharn
This probably works:

relation = 
Project.joins(:bids).group(Arel.sql('projects.id')).order(Arel.sql('count(bids.id)
 DESC'))

However, you might have to play around with it a bit if you need to put the 
`.includes(:bids, :user)` back in (or take the 1+N hit)

-Rob

> 
> On 2019-Jun-6, at 07:06 , Arup Rakshit  wrote:
> 
> I have a Project and Bid model.
> 
> Project has_many :bids
> Bid belongs_to project
> 
> I have now
>  relation = Project.includes(:bids, :user).references(:users, :bids)
> 
> What I now want is : select projects by ordering them with their bids count. 
> How can I write this query?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to rubyonrails-talk+unsubscr...@googlegroups.com 
> .
> To post to this group, send email to rubyonrails-talk@googlegroups.com 
> .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rubyonrails-talk/CAKxHnE1VBowD-dGZTFBgFBDVrznRj29HVBYprSphyJzxtGdD0w%40mail.gmail.com
>  
> .
> For more options, visit https://groups.google.com/d/optout 
> .

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/134FF291-A6DB-4825-AD1B-A153511FBB07%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Is there an administrator on this list?

2019-02-06 Thread Rob Biedenharn

Well, to be quite pedantic, fugee is more or a "help vampire" than a troll.
 
[ https://www.urbandictionary.com/define.php?term=help%20vampire ]( 
https://www.urbandictionary.com/define.php?term=help%20vampire )
 
-Rob B. (different from Rob J.)


-Original Message-
From: "Rob Jonson" 
Sent: Wednesday, 6 February, 2019 17:09
To: rubyonrails-talk@googlegroups.com
Subject: Re: [Rails] Is there an administrator on this list?



To be clear. I'm not suggesting that the behaviour _is_ trolling, just that the 
same solution might apply.
Lots of people (myself included) have tried to help by suggesting how to pose 
questions well after doing some homework. That clearly isn't getting through. 
In the absence of an admin to remove the individual, my suggestion is that 
everyone stops answering in the hope that he either learns some manners, or 
goes elsewhere.
It sounds like 'the ops on freenode' came to a similar conclusion. Clearly no 
lesson was learned.



__
Small phone.  Terse response.


On Wed, 6 Feb 2019, 9:50 pm Jake Niemiec <[ jniem...@warmlyyours.com ]( 
mailto:jniem...@warmlyyours.com ) wrote:
I don't think it feels like trolling. If anything, the responses by [ +Walter 
Davis ]( mailto:wa...@wdstudio.com ) 
are very informative.
In the last 30 days, fugee has opened 11 out of 45 threads. I would not 
characterize this as trolling, but I do think fugee needs to work on their 
google-fu.



On Wed, Feb 6, 2019 at 6:32 AM Rob Jonson <[ rob.jon...@gmail.com ]( 
mailto:rob.jon...@gmail.com )> wrote:
If so, I have a request:
I'm fed up of one persistent individual spamming the list with questions along 
the lines of 'Please do my work for me; I haven't done any preliminary 
investigation on my own'
If there is an administrator, please consider removing the individual from this 
list.
If there is no administrator, then my request to everyone else is to treat this 
like trolling, and just stop feeding the troll.
thanks,
Rob-- 
 You received this message because you are subscribed to the Google Groups 
"Ruby on Rails: Talk" group.
 To unsubscribe from this group and stop receiving emails from it, send an 
email to [ rubyonrails-talk+unsubscr...@googlegroups.com ]( 
mailto:rubyonrails-talk+unsubscr...@googlegroups.com ).
 To post to this group, send email to [ rubyonrails-talk@googlegroups.com ]( 
mailto:rubyonrails-talk@googlegroups.com ).
 To view this discussion on the web visit [ 
https://groups.google.com/d/msgid/rubyonrails-talk/9a330218-5f4c-452c-ac33-3d412b13408f%40googlegroups.com
 ]( 
https://groups.google.com/d/msgid/rubyonrails-talk/9a330218-5f4c-452c-ac33-3d412b13408f%40googlegroups.com?utm_medium=email_source=footer
 ).
 For more options, visit [ https://groups.google.com/d/optout ]( 
https://groups.google.com/d/optout ).-- 
 You received this message because you are subscribed to a topic in the Google 
Groups "Ruby on Rails: Talk" group.
 To unsubscribe from this topic, visit [ 
https://groups.google.com/d/topic/rubyonrails-talk/25e3esDCPq4/unsubscribe ]( 
https://groups.google.com/d/topic/rubyonrails-talk/25e3esDCPq4/unsubscribe ).
 To unsubscribe from this group and all its topics, send an email to [ 
rubyonrails-talk+unsubscr...@googlegroups.com ]( 
mailto:rubyonrails-talk+unsubscr...@googlegroups.com ).
 To post to this group, send email to [ rubyonrails-talk@googlegroups.com ]( 
mailto:rubyonrails-talk@googlegroups.com ).
 To view this discussion on the web visit [ 
https://groups.google.com/d/msgid/rubyonrails-talk/CALn2xuAX4xcQ46gnZHXCYnoji2jMRoGrVLUKZY_N%2BexfLtPG4Q%40mail.gmail.com
 ]( 
https://groups.google.com/d/msgid/rubyonrails-talk/CALn2xuAX4xcQ46gnZHXCYnoji2jMRoGrVLUKZY_N%2BexfLtPG4Q%40mail.gmail.com?utm_medium=email_source=footer
 ).
 For more options, visit [ https://groups.google.com/d/optout ]( 
https://groups.google.com/d/optout ).-- 
 You received this message because you are subscribed to the Google Groups 
"Ruby on Rails: Talk" group.
 To unsubscribe from this group and stop receiving emails from it, send an 
email to [ rubyonrails-talk+unsubscr...@googlegroups.com ]( 
mailto:rubyonrails-talk+unsubscr...@googlegroups.com ).
 To post to this group, send email to [ rubyonrails-talk@googlegroups.com ]( 
mailto:rubyonrails-talk@googlegroups.com ).
 To view this discussion on the web visit [ 
https://groups.google.com/d/msgid/rubyonrails-talk/CACTOy%2Bq%3DMUNFKff2-7PXjWaOsFGSt9Lz5WLV9WN3vhOhUhuV7w%40mail.gmail.com
 ]( 
https://groups.google.com/d/msgid/rubyonrails-talk/CACTOy%2Bq%3DMUNFKff2-7PXjWaOsFGSt9Lz5WLV9WN3vhOhUhuV7w%40mail.gmail.com?utm_medium=email_source=footer
 ).
 For more options, visit [ https://groups.google.com/d/optout ]( 
https://groups.google.com/d/optout ).

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send 

Re: [Rails] lookups in array

2018-05-15 Thread Rob Biedenharn


> On 2018-May-15, at 14:39 , Walter Lee Davis  wrote:
> 
> If you can put those into a hash, then you can look up values by their keys, 
> or vice-versa. Just call STATE_TYPES.to_h and then you have a hash where the 
> names are the keys, and the abbreviations are the values. If you call 
> STATE_TYPES.map(&:reverse).to_h, you will have the abbreviations as keys and 
> the names as values. In either case, you could then use index notation to get 
> a given key's value:
> 
> STATE_TYPES.to_h['Arizona']
> => 'AZ'
> 
> STATE_TYPES.map(&:reverse).to_h['AZ']
> => 'Arizona'
> 
> You don't need to call map or to_h every time, just make a new constant and 
> use it over and over:
> 
> STATES = STATE_TYPE.map(&:reverse).to_h
> 
> STATES['AZ']
> => 'Arizona'
> 
> Walter

Or you can take advantage of some other Ruby behavior:

The Hash[] constructor which will build a Hash from an Array of pairs (i.e., 
Arrays of two elements)
Hash#invert which returns a new hash with the values and keys swapped.

[3] pry(main)> STATE_TYPES = [ ['Alabama','AL'], ['Arizona','AZ'], 
['Ohio','OH'] ]
=> [["Alabama", "AL"], ["Arizona", "AZ"], ["Ohio", "OH"]]
[4] pry(main)> Hash[STATE_TYPES].invert
=> {"AL"=>"Alabama", "AZ"=>"Arizona", "OH"=>"Ohio"}
[5] pry(main)> Hash[STATE_TYPES].invert['OH']
=> "Ohio"

You might also want to look up Array#assoc and Array#rassoc which will operate 
directly on your array of pairs:

[6] pry(main)> STATE_TYPES.rassoc('OH')
=> ["Ohio", "OH"]
[7] pry(main)> STATE_TYPES.rassoc('OH').first
=> "Ohio"

-Rob

> 
>> On May 15, 2018, at 1:10 PM, fugee ohu  wrote:
>> 
>> I have an array of US States that looks likeSTATE_TYPES =   [
>> ['Alabama', 'AL'], ... ]
>> In views I need to display the State name from the value I have in the 
>> database, it's abbreviation
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ruby on Rails: Talk" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to rubyonrails-talk+unsubscr...@googlegroups.com.
>> To post to this group, send email to rubyonrails-talk@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/rubyonrails-talk/d7eea706-b4fa-4413-82e3-fda20742fb32%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to rubyonrails-talk+unsubscr...@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rubyonrails-talk/C870649E-8F80-414B-B671-C21B1E460C4F%40wdstudio.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/E90EF986-259D-41D0-84AA-4F5D5554C955%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Can you plz, explain to me part of this code ?

2018-04-26 Thread Rob Biedenharn


> On 2018-Apr-26, at 13:47 , Abdel Latif  wrote:
> 
> But [["AB_1020", "AB_950", "AB_50"], ["1000", "570"]] has non numerical 
> values too.
> 
> On Thursday, April 26, 2018 at 1:05:53 PM UTC-4, Walter Lee Davis wrote:
> 
> > On Apr 26, 2018, at 12:12 PM, Abdel Latif > wrote: 
> > 
> > Hi, 
> > 
> > I found this code for sorting an array : 
> > 
> > p ["AB_1020", "AB_950", "AB_50", "1000", "570"].partition{|x| x.to_i.zero? 
> > } 
> >   .flat_map{|x| x.sort_by {|x|x[/d+/]}.reverse} 

You're missing that String#[] when given a Regexp returns the substring that 
matches that Regexp.

[1] pry(main)> ["AB_1020", "AB_950", "AB_50",].map {|x| x[/\d+/]}
=> ["1020", "950", "50"]
[2] pry(main)> ["AB_1020", "AB_950", "AB_50",].map {|x| x[/\d+/]}.sort
=> ["1020", "50", "950"]
[3] pry(main)> ["AB_1020", "AB_950", "AB_50",].map {|x| x[/\d+/]}.sort.reverse
=> ["950", "50", "1020"]
[4] pry(main)> ["AB_1020", "AB_950", "AB_50",].map {|x| 
x[/\d+/].to_i}.sort.reverse
=> [1020, 950, 50]
[5] pry(main)> ["AB_1020", "AB_950", "AB_50",].sort_by {|x| x[/\d+/].to_i}
=> ["AB_50", "AB_950", "AB_1020"]

-Rob

> > ouptut 
> > 
> > #⇒ ["AB_50", "AB_950", "AB_1020", "570", "1000"] 
> > 
> > 
> > I know that .partition{|x| x.to_i.zero? } will create an array of arrays : 
> > [["AB_1020", "AB_950", "AB_50"], ["1000", "570"]] 
> > 
> > 
> > But this part .flat_map{|x| x.sort_by {|x|x[/d+/]}.reverse} 
> 
> flat_map: https://apidock.com/ruby/Enumerable/flat_map 
>  
> 
> Then that passes a block, which acts on each member of the Enumerable that 
> called flat_map. That block sorts by the numerical value of x, then reverses. 
> 
> Does that help? 
> 
> Walter 
> 
> > 
> > I could understand it. 
> > 
> > Thanks. 
> > 
> > -- 
> > You received this message because you are subscribed to the Google Groups 
> > "Ruby on Rails: Talk" group. 
> > To unsubscribe from this group and stop receiving emails from it, send an 
> > email to rubyonrails-ta...@googlegroups.com <>. 
> > To post to this group, send email to rubyonra...@googlegroups.com <>. 
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msgid/rubyonrails-talk/c8e2dc7d-8501-4df3-b19c-917ebded457f%40googlegroups.com
> >  
> > .
> >  
> > For more options, visit https://groups.google.com/d/optout 
> > . 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to rubyonrails-talk+unsubscr...@googlegroups.com 
> .
> To post to this group, send email to rubyonrails-talk@googlegroups.com 
> .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rubyonrails-talk/f6fa4cc4-37b2-4828-ba1c-f9ac0d780221%40googlegroups.com
>  
> .
> For more options, visit https://groups.google.com/d/optout 
> .

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/F584BA16-90B8-40DD-8C04-A92CBF336241%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] help: ActionController::UnknownFormat in FooController#index

2018-03-05 Thread Rob Biedenharn


> On 2018-Mar-5, at 13:15 , Hassan Schroeder  wrote:
> 
> On Mon, Mar 5, 2018 at 9:59 AM, tom  wrote:
>> so how can i pass this along? why is it not assuming html?
> 
> Because computers don't make assumptions?  
> 
> Why are you telling it to respond differently depending on the format
> and then *not providing a format*??
> 
> -- 
> Hassan Schroeder  hassan.schroe...@gmail.com
> twitter: @hassan
> Consulting Availability : Silicon Valley or remote

> Started GET "/whatever/in/St.%20Peters" for 10.0.1.37 at 2018-03-05 12:09:39 
> -0500
> Processing by FooController#index as

You really should have added one more line from the log here.

It was very likely looking for a :format => '%20Peters" because of the '.' in 
the URL path.

Look at the output from `rails routes` to see the various ways that you might 
be routing to foos#index

Another way to fix this tends to "break" having multiple formats. You can add:

> eg:
>   match  'whatever/in/:seoterm'   , as: 'seo_whatever _in'  , :to => 
> 'foos#index', via: [:get]  , :mode=>{:x=>' whatever ',:y=>1}

, constraints: { seoterm: /.+/ }

so that :seoterm slurps all the remaining characters of the URL. This breaks 
the "implicit" (.:format) that gets added because the constraint will match the 
'.' and everything after it leaving nothing to match the "optional" format.

-Rob

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/45979B90-B83A-4EB9-9770-7E2C222E0620%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] find_or_create_by rolls back

2018-02-01 Thread Rob Biedenharn

> On 2018-Feb-1, at 09:05 , fugee ohu  wrote:
> 
> 
> 
> On Thursday, February 1, 2018 at 8:54:56 AM UTC-5, Colin Law wrote:
> On 1 February 2018 at 13:49, fugee ohu  
> wrote:
> 
> 
> On Thursday, February 1, 2018 at 3:51:37 AM UTC-5, Colin Law wrote:
> On 1 February 2018 at 07:30, fugee ohu > wrote:
> I'm having find_or_create_by roll back on me in the console directly from the 
> model I'm not providing an id, the mysql id column is autoincrement
> Model.find_or_create_by(person_id: 1, picture_id:37)
> 
> What happens if you try and create a record (where there is not already a 
> matching record) with only those fields?
> 
> Colin
>  
> 
> Same thing It works only if I remove all the belongs_to from Model 
> 
> Have you got any validations on the model?
> Can you show us the model code where it has the associations and validations?
> 
> What do you see in the log when you try to do it?
> 
> Colin
>  
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to rubyonrails-ta...@googlegroups.com .
> To post to this group, send email to rubyonra...@googlegroups.com 
> .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rubyonrails-talk/aa095ea1-5568-402a-978f-9c6f794a8eb6%40googlegroups.com
>  
> .
> 
> For more options, visit https://groups.google.com/d/optout 
> .
> 
> 
> class Relationship < ApplicationRecord
>   belongs_to  :picture
>   belongs_to  :person
>   belongs_to  :address
>   belongs_to  :car
> end

Does your database have foreign keys set up for these?

Look at the end of your `db/schema.rb` file for lines like:

  add_foreign_key "relationships", "pictures"
  add_foreign_key "relationships", "people"
  add_foreign_key "relationships", "addresses"
  add_foreign_key "relationships", "cars"

If you don't have Person:1 or Picture:10, then this Relationship can't be 
created.

If you are actually trying to make Relationship be "generic", then you might 
try something like:

class Relationship < ApplicationRecord
  belongs_to :person
  belongs_to :thing, polymorphic: true
end

(Not that I'm necessarily recommending you do this as I don't know your 
requirements.)


> class Person < ApplicationRecord
>  has_many :real_estate_transactions
>  has_many :relationships
>  has_many :pictures, through: :relationships
>  has_many :addresses, through: :relationships
>  has_many :cars, through: :relationships
>  attr_accessor :address_id
>  attr_accessor  :person_id
>  attr_accessor  :car_id
>  attr_accessor  :picture_id
>  def formatted_name
>   "#{last_name}, #{first_name}, #{middle_name}, #{name}"
>  end
> 
> end

Also, why do you have all those `attr_accessor` for the various _id's? If a 
Person has many Pictures, then there isn't any _single_ picture_id for a 
person. ActiveRecord will give you an implicit `picture_ids` based on the 
`has_many` (though it's not likely that you need that much).

-Rob

> 
> class Picture < ApplicationRecord
>  validates :name, presence: true
>  has_many :relationships
>  has_many :people, through: :relationships
>  has_many :cars, through: :relationships
>  mount_uploader :name, PictureUploader
>  attr_accessor  :person_id
>  attr_accessor  :car_id
>  attr_accessor  :picture_id
>   
>  def formatted_name
>   "#{name}, #{id}"
>  end
> 
> end
> 
> rails c
> 2.3.3 :001 > Relationship.find_or_create_by(person_id: 1, picture_id: 10)
>   Relationship Load (144.3ms)  SELECT  `relationships`.* FROM `relationships` 
> WHERE `relationships`.`person_id` = 1 AND `relationships`.`picture_id` = 10 
> LIMIT 1
>(1.1ms)  BEGIN
>   Picture Load (27.0ms)  SELECT  `pictures`.* FROM `pictures` WHERE 
> `pictures`.`id` = 10 LIMIT 1
>   Person Load (5.0ms)  SELECT  `people`.* FROM `people` WHERE `people`.`id` = 
> 1 LIMIT 1
>(25.6ms)  ROLLBACK
>  => # real_estate_transaction_id: nil, car_id: nil, event_id: nil, picture_id: 10> 
> 2.3.3 :002 > 
>  
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to rubyonrails-talk+unsubscr...@googlegroups.com 
> .
> To post to this group, send email to rubyonrails-talk@googlegroups.com 
> .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rubyonrails-talk/dc85a890-8591-4543-b5de-1fce1662a64e%40googlegroups.com
>  
> .
> For more 

Re: [Rails] routes

2017-09-12 Thread Rob Biedenharn
I'm removing most of the "noise" from your output and focussing on the 
gallery-relevant bits:

> On 2017-Sep-12, at 17:29 , Joe Guerra  wrote:
> 
> here's the output of my routes... (sorry about the formatting)
> 
> Prefix Verb   URI Pattern 
> Controller#Action
> gallery_index GET/gallery(.:format)  gallery#index
>   POST   /gallery(.:format)  
> gallery#create
>   new_gallery GET/gallery/new(.:format)  gallery#new
>  edit_gallery GET/gallery/:id/edit(.:format) gallery#edit
>   gallery GET/gallery/:id(.:format)  gallery#show
>   PATCH  /gallery/:id(.:format)  
> gallery#update
>   PUT/gallery/:id(.:format)  
> gallery#update
>   DELETE /gallery/:id(.:format)  
> gallery#destroy

the key bit to notice is that the index route is "named" gallery_index because 
you used:

resources :gallery

and :gallery is the singular form

You very likely want to say instead:

resources :galleries

which will give you similar routes *except* from the index:

[ruby-2.4.1p111] //tmp $ cd example/
[ruby-2.4.1p111] tmp/example (master #%) $ rails g resources Gallery
Running via Spring preloader in process 61722
Could not find generator 'resources'. Maybe you meant 'resource', 
'resource_route' or 'assets'
Run `rails generate --help` for more options.
[ruby-2.4.1p111] tmp/example (master #%) $ rails g resource Gallery
Running via Spring preloader in process 61823
  invoke  active_record
  createdb/migrate/20170912230824_create_galleries.rb
  createapp/models/gallery.rb
  invoketest_unit
  create  test/models/gallery_test.rb
  create  test/fixtures/galleries.yml
  invoke  controller
  createapp/controllers/galleries_controller.rb
  invokeerb
  create  app/views/galleries
  invoketest_unit
  create  test/controllers/galleries_controller_test.rb
  invokehelper
  create  app/helpers/galleries_helper.rb
  invoke  test_unit
  invokeassets
  invoke  coffee
  createapp/assets/javascripts/galleries.coffee
  invoke  scss
  createapp/assets/stylesheets/galleries.scss
  invoke  resource_route
   routeresources :galleries
[ruby-2.4.1p111] tmp/example (master #%) $ cat config/routes.rb 
Rails.application.routes.draw do
  resources :galleries
  # For details on the DSL available within this file, see 
http://guides.rubyonrails.org/routing.html
end
[ruby-2.4.1p111] tmp/example (master #%) $ rails routes
  Prefix Verb   URI Pattern   Controller#Action
   galleries GET/galleries(.:format)  galleries#index
 POST   /galleries(.:format)  galleries#create
 new_gallery GET/galleries/new(.:format)  galleries#new
edit_gallery GET/galleries/:id/edit(.:format) galleries#edit
 gallery GET/galleries/:id(.:format)  galleries#show
 PATCH  /galleries/:id(.:format)  galleries#update
 PUT/galleries/:id(.:format)  galleries#update
 DELETE /galleries/:id(.:format)  galleries#destroy


Note the routes for index, create, and new ^^

-Rob

> 
> On Tuesday, September 12, 2017 at 5:03:56 PM UTC-4, Colin Law wrote:
> On 12 September 2017 at 02:15, Joe Guerra  > wrote: 
> > ... 
> > I'm using... in my routes file. 
> > 
> > get resources :gallery 
> 
> Why is the 'get' there? 
> 
> Colin 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to rubyonrails-talk+unsubscr...@googlegroups.com 
> .
> To post to this group, send email to rubyonrails-talk@googlegroups.com 
> .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rubyonrails-talk/af2a8305-0b83-4075-8b51-f0b610ac31a7%40googlegroups.com
>  
> .
> For more options, visit https://groups.google.com/d/optout 
> .

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/9D2B37D1-18F3-4FC0-9E65-31E73C9DB0D1%40gmail.com.

Re: [Rails] confused

2017-07-11 Thread Rob Biedenharn

> On 2017-Jul-11, at 14:52 , 'Bigos' via Ruby on Rails: Talk 
>  wrote:
> 
> output.each{|o| o.map!{|i| {:space_nickname => i.space.nickname, 
> :nickname => i.nickname, :condition_number => i.condition,
> :condition => 
> report_config.slider_order[i.condition][1],
> :full_note => "#{i.full_note.strip} \n 
> #{i.photos.select{|p| !p.caption.blank? }.map{|p|
>   "[Photo 
> #{photo_number_for(report.photo_numbers.hash, p)}] #{p.caption}"
> }.compact.join("\n")}".strip,
> :description => i.description, :trade => 
> i.trade, :flagged => !i.require_maintenance.blank? }}}
> output.reject(&:empty?)
> 
> My coworker says it is valid Ruby, but Emacs highliting gets mangled. Does 
> anybody know where I should report issues with that? I could only find an svn 
> repo for that particular plugin for Emacs.  


Where is the closing quote for the line that starts with:
:full_note => "
If you have "nested" quotes inside interpolations, perhaps you need to use %{} 
instead of ""

Or, perhaps even better, don't try to be so clever and compact:

output.each {|o|
  o.map! {|i|
full_note = [i.full_note.strip]
i.photos.each do |photo|
  next if photo.caption.blank?
  full_note <<  "[Photo #{photo_number_for(report.photo_numbers.hash, 
photo)}] #{photo.caption}"
end
{
  :space_nickname => i.space.nickname,
  :nickname => i.nickname,
  :condition_number => i.condition,
  :condition => report_config.slider_order[i.condition][1],
  :full_note => full_note.join("\n").strip,
  :description => i.description,
  :trade => i.trade,
  :flagged => !i.require_maintenance.blank?
}
  }
}
output.reject(&:empty?)

-Rob

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CC271BE7-2666-43A3-84F3-3CC9BC760516%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] acts_as_commentable_with_threading

2017-06-29 Thread Rob Biedenharn
> On 2017-Jun-29, at 10:59 , fugee ohu <fugee...@gmail.com> wrote:
> On Wednesday, June 28, 2017 at 10:09:25 AM UTC-4, Rob Biedenharn wrote:
>> On 2017-Jun-28, at 01:51 , fugee ohu <fuge...@gmail.com <>> wrote:
>> 
>> On Monday, June 26, 2017 at 9:43:19 AM UTC-4, Rob Biedenharn wrote:
>> At this point, you should be able to look around a small codebase like this 
>> and figure it out, but here are the "hints":
>> 
>> https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/controllers/beers_controller.rb#L6
>>  
>> <https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/controllers/beers_controller.rb#L6>
>> 
>> https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/views/beers/show.html.erb#L6
>>  
>> <https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/views/beers/show.html.erb#L6>
>> 
>> https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/views/comments/_template.html.erb#L7
>>  
>> <https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/views/comments/_template.html.erb#L7>
>> 
>> https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/views/comments/_form.html.erb
>>  
>> <https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/views/comments/_form.html.erb>
>> 
>> If you don't get how this is working, point to a specific thing and ask a 
>> more directed question.
>> 
>> -Rob
>> 
>> P.S. The routes could easily be amended to be:
>> resources :comments, except: [:new]
>> 
>>> On 2017-Jun-25, at 22:04 , fugee ohu <fuge...@ <>gmail.com 
>>> <http://gmail.com/>> wrote:
>>> 
>>> I'm looking at the Dustin Fisher example app on github 
>>> https://github.com/DustinFisher/acts-as-commentable-with-threading-example/tree/master/
>>>  
>>> <https://github.com/DustinFisher/acts-as-commentable-with-threading-example/tree/master/>
>>>  but his comments_controller.rb has no new action Can someone clarify 
>>> please?
>>> 
>> 
>> 
>> I put a new action in the comments controller since you don't use a link to 
>> new you render the form instead
> 
> Unless you're changing other parts, too. You will NEVER hit the :new action 
> because you ALWAYS create the comment form in the context of a Post or 
> another Comment. Like I said, you could add `, except: [:new]` to the route 
> if it bothers you.
> -Rob
> 
> 
>  So in your example the forms already on the page in index view instead of a 
> link to new comment? If yes whats wrong with a link to new comment instead of 
> a text area and submit button already rendered?

If you do that, you need to pass the "parent" object to the `new` action. 
There's nothing "wrong" with that. You probably need to define your own 
new_comment route if you want the URL to look nice and not have query 
parameters to define the parent object. (If you intend to eliminate threaded 
comments where the parent is another comment, you have just a little more work 
to do, but then you might not even need Comment to be polymorphic [if you can't 
comment on more than one kind of model].)

-Rob

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/6865135D-828C-4D4D-9B75-0A8FE25F5F40%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] acts_as_commentable_with_threading

2017-06-28 Thread Rob Biedenharn

> On 2017-Jun-28, at 01:51 , fugee ohu <fugee...@gmail.com> wrote:
> 
> On Monday, June 26, 2017 at 9:43:19 AM UTC-4, Rob Biedenharn wrote:
> At this point, you should be able to look around a small codebase like this 
> and figure it out, but here are the "hints":
> 
> https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/controllers/beers_controller.rb#L6
>  
> <https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/controllers/beers_controller.rb#L6>
> 
> https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/views/beers/show.html.erb#L6
>  
> <https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/views/beers/show.html.erb#L6>
> 
> https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/views/comments/_template.html.erb#L7
>  
> <https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/views/comments/_template.html.erb#L7>
> 
> https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/views/comments/_form.html.erb
>  
> <https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/views/comments/_form.html.erb>
> 
> If you don't get how this is working, point to a specific thing and ask a 
> more directed question.
> 
> -Rob
> 
> P.S. The routes could easily be amended to be:
> resources :comments, except: [:new]
> 
>> On 2017-Jun-25, at 22:04 , fugee ohu <fuge...@ <>gmail.com 
>> <http://gmail.com/>> wrote:
>> 
>> I'm looking at the Dustin Fisher example app on github 
>> https://github.com/DustinFisher/acts-as-commentable-with-threading-example/tree/master/
>>  
>> <https://github.com/DustinFisher/acts-as-commentable-with-threading-example/tree/master/>
>>  but his comments_controller.rb has no new action Can someone clarify please?
>> 
> 
> 
> I put a new action in the comments controller since you don't use a link to 
> new you render the form instead

Unless you're changing other parts, too. You will NEVER hit the :new action 
because you ALWAYS create the comment form in the context of a Post or another 
Comment. Like I said, you could add `, except: [:new]` to the route if it 
bothers you.
-Rob

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/599F07B9-686A-4DE1-AB37-0051EE73625F%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] acts_as_commentable_with_threading

2017-06-28 Thread Rob Biedenharn

> On 2017-Jun-28, at 01:49 , fugee ohu <fugee...@gmail.com> wrote:
> 
> 
> 
> On Monday, June 26, 2017 at 9:43:19 AM UTC-4, Rob Biedenharn wrote:
> At this point, you should be able to look around a small codebase like this 
> and figure it out, but here are the "hints":
> 
> https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/controllers/beers_controller.rb#L6
>  
> <https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/controllers/beers_controller.rb#L6>
> 
> https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/views/beers/show.html.erb#L6
>  
> <https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/views/beers/show.html.erb#L6>
> 
> https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/views/comments/_template.html.erb#L7
>  
> <https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/views/comments/_template.html.erb#L7>
> 
> https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/views/comments/_form.html.erb
>  
> <https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/views/comments/_form.html.erb>
> 
> If you don't get how this is working, point to a specific thing and ask a 
> more directed question.
> 
> -Rob
> 
> P.S. The routes could easily be amended to be:
> resources :comments, except: [:new]
> 
>> On 2017-Jun-25, at 22:04 , fugee ohu <fuge...@ <>gmail.com 
>> <http://gmail.com/>> wrote:
>> 
>> I'm looking at the Dustin Fisher example app on github 
>> https://github.com/DustinFisher/acts-as-commentable-with-threading-example/tree/master/
>>  
>> <https://github.com/DustinFisher/acts-as-commentable-with-threading-example/tree/master/>
>>  but his comments_controller.rb has no new action Can someone clarify please?
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ruby on Rails: Talk" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to rubyonrails-ta...@ <>googlegroups.com <http://googlegroups.com/>.
>> To post to this group, send email to rubyonra...@ <>googlegroups. 
>> <http://googlegroups.com/>com <http://googlegroups.com/>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/rubyonrails-talk/6554adbe-6847-4925-bbaa-097b583eda93%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/rubyonrails-talk/6554adbe-6847-4925-bbaa-097b583eda93%40googlegroups.com?utm_medium=email_source=footer>.
>> For more options, visit https://groups.google.com/d/optout 
>> <https://groups.google.com/d/optout>.
> 
> 
> Why does comments/_reply.html.erb have to recursively render itself again 
> after the form ?

Because you can reply to a comment and then someone could reply to your reply, 
etc. Note that the recursive call is only for the comment.children so it won't 
go on forever.
-Rob

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/8F2238F5-3052-4D31-BCBB-597FD943D461%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] acts_as_commentable_with_threading

2017-06-26 Thread Rob Biedenharn
At this point, you should be able to look around a small codebase like this and 
figure it out, but here are the "hints":

https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/controllers/beers_controller.rb#L6
 


https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/views/beers/show.html.erb#L6
 


https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/views/comments/_template.html.erb#L7
 


https://github.com/DustinFisher/acts-as-commentable-with-threading-example/blob/master/app/views/comments/_form.html.erb
 


If you don't get how this is working, point to a specific thing and ask a more 
directed question.

-Rob

P.S. The routes could easily be amended to be:
resources :comments, except: [:new]

> On 2017-Jun-25, at 22:04 , fugee ohu  wrote:
> 
> I'm looking at the Dustin Fisher example app on github 
> https://github.com/DustinFisher/acts-as-commentable-with-threading-example/tree/master/
>  but his comments_controller.rb has no new action Can someone clarify please?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to rubyonrails-talk+unsubscr...@googlegroups.com 
> .
> To post to this group, send email to rubyonrails-talk@googlegroups.com 
> .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rubyonrails-talk/6554adbe-6847-4925-bbaa-097b583eda93%40googlegroups.com
>  
> .
> For more options, visit https://groups.google.com/d/optout 
> .

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/A1A7376F-71CF-4870-8A2F-B596358805FF%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] changing mysql engine and options in schema.rb

2017-04-10 Thread Rob Biedenharn

> On 2017-Apr-8, at 13:45 , Walter Lee Davis  wrote:
> 
> 
>> On Apr 7, 2017, at 11:03 PM, fugee ohu  wrote:
>> 
>> Also, of course I need the id's from the dumpfile to be inserted as the same 
>> values otherwise all relations would be borked

fugee,

This statement reveals the problem with your thinking on this.

AUTO_INCREMENT only takes place when the `id` is *not given* in the data.

ActiveRecord does not normally assign a value to the `id` and simply reflects 
the value assigned by the underlying database upon being saved. (I.e., INSERTed)

In Rails, the migrations are fundamentally *database* migrations, not _data_ 
migrations. (Though you can add or manipulate data within a migration, that is 
certainly *not* their primary purpose.)

As Walter points out, the db/seeds.rb file can be used to populate data, but 
that is typically minimal to get the system bootstrapped. Loading data from 
some other source is probably best approached as a stand-alone script that can 
be run once.

-Rob

> 
> You seem to be going at this all sideways. When you stand up a server, you 
> run the migrations on that server in the production environment. That 
> connects to the production server, creates the database (which means it will 
> have entirely no content in the tables, thus no need to artificially alter 
> the auto-increment start point) and builds all the tables from scratch.
> 
> Drop your database. Run the migrations on the server in the production 
> environment. Please. You are hurting yourself, and it's difficult to watch.
> 
> Adding data to the database (in order to mirror an existing data set 
> elsewhere, or to set up some base accounts or relationships) is the job of 
> the seeds.rb file. You run that separately, after you have created the 
> database and all its tables, and you can put whatever IDs or relationships in 
> there that you need.
> 
> Editing the schema.rb file is a mistake, plain and simple. Think of this file 
> as a log, showing all of the migrations run to date in a single place. Yes, 
> you will find some examples out there where people use it to stand up their 
> db server "in a hurry". But look at all the time you have spent trying to 
> force-fit it into a purpose that it really should not serve! Run the 
> migrations. That's what they are for. Use seeds to populate data if you need 
> to. Don't cross the streams. Migrations are designed to be idempotent. Run 
> them once, or many times, and you will get the same result. The schema is 
> just a record of the current state, not a tool to be used to duplicate that 
> database. And editing it should set off all sorts of warning bells, because 
> the very next migration you create in your project will entirely erase that 
> file and re-create it from scratch, deleting all of your changes.
> 
> Walter
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to rubyonrails-talk+unsubscr...@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rubyonrails-talk/9BF2CA04-E424-4D73-BA71-64E52BDA1B0A%40wdstudio.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/4F536876-AC7C-4A46-BE83-AA22E5745F3C%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] changing mysql engine and options in schema.rb

2017-04-07 Thread Rob Biedenharn

> On 2017-Apr-7, at 15:26 , fugee ohu  wrote:
> 
> 
> 
> On Friday, April 7, 2017 at 3:02:50 PM UTC-4, Walter Lee Davis wrote:
> Those options are all part of create database, which you would run once, not 
> on every migration. I have usually seen them set at the server level, in the 
> database's ini file. 
> 
> Walter 
> 
> > On Apr 7, 2017, at 2:59 PM, fugee ohu  
> > wrote: 
> > 
> > Trying to get the right syntax for something like this to put in schema.rb 
> > for mysql2 
> > 
> > ENGINE=InnoDB DEFAULT CHARSET=utf8 PRIMARY KEY=ID AUTOINCREMENT 
> > 
> > this isn't valid syntax, anyone can correct? additionally i want id to be 
> > int(11) and i want the sql-mode traditional 
> > 
> > thanks in advance 
> > 

> Hey Walter thanks, Until I learn how to set the server can you give me the 
> migrations syntax for each create table statement please, i have something in 
> mind similar to this pseudo-line
>   create_table "bios", force: :cascade, options: "ENGINE=InnoDB DEFAULT 
> CHARSET=utf8 PRIMARY KEY=ID AUTOINCREMENT" do |t|
> thanks in advance 

Here's an idea for you: Run the migration and then look into the db/schema.rb 
file and compare that to the migration and to the actual database table.

It would save time for everyone if you tried some of this yourself and then, if 
it doesn't make sense, you can say what you did, show the output, explain why 
you are confused (and what you expected), and then ask for help.

-Rob

For example:

In the migration file:

class CreateLanguages < ActiveRecord::Migration
  def change
create_table :languages do |t|
  t.string :iso
  t.string :name
end
add_index :languages, :iso
  end
end

db/schema.rb

  create_table "languages", force: :cascade, options: "ENGINE=InnoDB DEFAULT 
CHARSET=utf8 COLLATE=utf8_unicode_ci" do |t|
t.string "iso"
t.string "name"
t.index ["iso"], name: "index_languages_on_iso", using: :btree
  end

MySQL

mysql> show create table languages\G
*** 1. row ***
   Table: languages
Create Table: CREATE TABLE `languages` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `iso` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `index_languages_on_iso` (`iso`)
) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
1 row in set (0.00 sec)

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/6AEA39AE-50EC-4B59-8CB4-82FAFBD1064E%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] update query

2017-03-03 Thread Rob Biedenharn

> On 2017-Mar-3, at 09:46 , Joe Guerra  wrote:
> 
> 
> I'm not sure why I'm getting this... I'm trying to update a product in the 
> ruby console (and tried it within my app).

> NoMethodError: undefined method `Startdate' for #
> 
> 
> Did you mean?  startdate
> 
> 
>startdate?
> 
> 
>startdate=
> 
> 
>startdate_was
> 
> 
>startdate_change
> 
> 
>startdate_changed?
> 
> 
>Startdate=
> 
> 
> from 
> /Users/joeguerra/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activemodel-4.2.5/lib/active_model/attribute_methods.rb:433:in
>  `method_missing'
> 
> 
> At one point my table for product had a 'Startdate' column, but I ran a 
> migration to change that column to all lowercase.
> 
> any ideas?

Note that "Startdate=" remains as a suggested alternative. I'd start by 
searching your code for the case-sensetive 'Startdate'

-Rob


-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CFEF0333-D60B-40CE-A882-B4BFC1FCF2A2%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] vertical align a link_to(image_tag

2017-03-02 Thread Rob Biedenharn

> On 2017-Mar-2, at 19:00 , fugee ohu  wrote:
> 
> don't know why i can't get this image to vertical-align to the top of the 
> div, i'm not sure if i'm passing the class the right way
> 
> here's my html
> <%= link_to (image_tag("logo.png")), '/' ,  {:class => "logo"} %>

Actually, that's your ERB, not the HTML

Did you mean to have redundant () around the image_tag("logo.png")?

Also, that class is on the resulting  tag, not the img so that might make a 
difference if there's other CSS that affects img or a elements.

-Rob

> 
> here's my css
> 
> .logo {
> vertical-align: top;
> height: 100%;
> }
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to rubyonrails-talk+unsubscr...@googlegroups.com 
> .
> To post to this group, send email to rubyonrails-talk@googlegroups.com 
> .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rubyonrails-talk/99b5ec4a-2d03-48a2-86c3-32fc21b47782%40googlegroups.com
>  
> .
> For more options, visit https://groups.google.com/d/optout 
> .

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/ED85427E-39B2-45C4-89C7-8E7D4E74AD9A%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] ruby embedded conditionals

2017-02-09 Thread Rob Biedenharn

> On 2017-Feb-9, at 12:10 , Joe Guerra  wrote:
> 
> I can't get my embedded  if statement working  in a html table.
> 
> here's one row of my table from my cart index...
> 
> <%= cart.created_at.strftime("%m/%d/%Y")%> |  <%=  cart.product_id  
> %> |  <% if cart.processing == 'true'%> <%= Processing order %>  <% end 
> %>
> 
> basically I want to indicate when an item is being processed in the cart... 
Try it like this:
<%= cart.created_at.strftime("%m/%d/%Y") %> | <%= cart.product_id %> | <%= 
'Processing order' if cart.processing == 'true'%>
Also, why is cart.processing returning a string? (Or why are you testing the 
value is 'true'?) It would be more natural to have cart.processing? be truthy.

-Rob

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/8E2412B3-0B51-4BA8-850C-185E5DAF38F0%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] local sqlite development vs Heroku PG deployment

2017-02-01 Thread Rob Biedenharn
> On 2017-Feb-1, at 18:24 , Walter Lee Davis  wrote:
> 
>> On Jan 31, 2017, at 10:55 PM, Joe Guerra  wrote:
>> 
>> ok, I solved of my problems.  My git commit / push didn't work.  Thats 
>> working now.
>> 
>> 
>> the other thing is...
>> 
>> ActionView::Template::Error (PG::UndefinedColumn: ERROR:  column "startdate" 
>> does not exist
>> 2017-02-01T03:51:33.326023+00:00 app[web.1]: LINE 1: SELECT  "products".* 
>> FROM "products"  ORDER BY Startdate ASC...
>> 2017-02-01T03:51:33.326023+00:00 app[web.1]: 
>>^
>> 2017-02-01T03:51:33.326024+00:00 app[web.1]: HINT:  Perhaps you meant to 
>> reference the column "products.Startdate".
>> 
>> Startdate is a column in my database table, I don't know where it coming up 
>> with 'startdate' does not exist?  I don't have that in any of my references.
>> 
>> Thanks,
>> Joe
>> 
>> On Tuesday, January 31, 2017 at 10:24:13 PM UTC-5, Joe Guerra wrote:
>> This is driving me crazy.  I have my web app working great in development, 
>> then I commit and push it to Github and heroku automatically deploys my app.
>> 
>> Unfortunately, it doesn't quite work out the same as the development.  
>> 
>> Pages aren't being found on production, but they are there in development 
>> and they are on my github repo.  
>> 
>> Heroku logs are not very useful either.  :(
>> 
>> Any suggestions?
> 
> Are you using capital letters in your table names? You're going to have to do 
> some extra work to get that to work, because the standard is lower-case table 
> names. Some RDBMs don't care what case you use for table names, but some do.
> 
> Walter

In particular, see 
https://blog.xojo.com/2016/09/28/about-postgresql-case-sensitivity/

-Rob

> 
>> 
>> Thanks,
>> Joe

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/E79DB830-C75E-4840-9FDD-4269425EF9E2%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Calling 'sanitize' on collection_radio_buttons text_method

2016-10-27 Thread Rob Biedenharn

> On 2016-Oct-27, at 08:26 , Serguei Cambour  wrote:
> 
> I figured out how to achieve that:
> 
> <%= f.collection_radio_buttons :name, [[true, 'H2O'] ,[false, 
> 'SO2']],:first, :last do |b| %>
> <%= b.label {b.radio_button + sanitize(b.text, tags: %w(sub sup))}%>
>   <%end%>

> On Wednesday, 26 October 2016 12:45:48 UTC+2, Serguei Cambour wrote:
> How is it possible to call sanitize on the below collection_radio_buttons 
> method:
> 
> = f.collection_radio_buttons :answer_ids, @question.answers, :id
> 
> 
> 
> I tried as follows and it failed:
> 
> = f.collection_radio_buttons :answer_ids, @question.answers, :id, 
> sanitize(:text, tags: %w(subsup))
> 
> Any idea? Thank you.


While I wouldn't normally suggest this for user-supplied data, you could change 
the Answer#text to return .sanitize'd strings:

class Answer

  include ActionView::Helpers::SanitizeHelper 
  def text
sanitize 
(read_attribute(:text),
 tags: %w[sub sup])
  end

end

I think that this will work, but I haven't tried it myself.

-Rob

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/769EB566-13B5-45A6-98EF-2AA688E81EC9%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] incorrect number of arguments

2016-06-29 Thread Rob Biedenharn

> About the end, its could be that a 'do' is missing a 'else' is incorrect, or 
> a missed an 'end' somewhere.
> 
> On Wed, Jun 29, 2016 at 4:39 PM, Ruth Stephenson  > wrote:
> Than you so much for your reply and your help! I'm still a little
> confused however as I'm still getting an error:
> 
> syntax error, unexpected end-of-input, expecting keyword_end
> 
> I don't know why it's complaining about end keywords. As far as I can
> tell they are ok.

> appointments controller:
> 
> def create  #(needs end 1)
> @appointment = Appointment.new(appointment_params)
> 
>   respond_to do |format|  #(needs end 2)
>   unless @appointments.isValid?  #(needs end 3)
> 
> 
> 
> if @appointment.save  #(needs end 4)
>   format.html { redirect_to @appointment, notice: 'Appointment
> was successfully created.' }
>   format.json { render :show, status: :created, location:
> @appointment }
> elsif
>   format.html { render :new }
>   format.json { render json: @appointment.errors, status:
> :unprocessable_entity }
> else
>   redirect_to root_path
> end #(end 4)
> end #(end 3)
>   end #(end 2)

Where is "end 1"?  Your indentation is hiding the problem from you as the 
"unless..." isn't indented further than the "respond_to do ..."

-Rob


-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/D7B78BC4-265A-4E5C-8447-0E0A7D0001D2%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Sending parameters to controller using link_to but getting the variable name itself.

2016-06-22 Thread Rob Biedenharn
> On 2016-Jun-22, at 04:20 , Padmahas Bn  wrote:
> 
> Hi,
> 
> I'm not using any form in this web page. I only have labels, text boxes and 
> links with parameters.
> The text_field code is
> 
> <%= label_tag("Member code") %>
> <%= text_field_tag :member_code, nil, class: 
> 'form-control'%>
> 
> 
> The link_to code is
> 
> <%= link_to "Joint and Personal loan (Ajax not implemented)", 
> jlpl_prints_path(member_code: 'member_code'), :class => "btn btn-danger", 
> method: :post %>

You want to remove the quotes from the value:
member_code: 'member_code'
and just have:
member_code: member_code

However, you will have a form in your page due to the use of method: :post in 
your link_to; it's just a generated form.

As others have said, you'll need to do some Javascript (perhaps with a library 
like jQuery) to get the value of a field at the time the link is clicked 
without using a form.

-Rob

> in the controller I printed member_code to verify whats the value I'm getting.
> member_code = params[:member_code]
> puts"***Inside controller member_code received is #{member_code} 
> **"
> 
> The thing is its printing the output in the console as 
> **Inside controller member_code received is 
> member_code**
> 
> Why is that? I've filled text_field with value 180 but I'm getting the 
> variable itself but not the value of it. Is form_tag is necessary to get this 
> to work?
> 
> Thank you.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to rubyonrails-talk+unsubscr...@googlegroups.com 
> .
> To post to this group, send email to rubyonrails-talk@googlegroups.com 
> .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rubyonrails-talk/3e05f0ea-f2f7-401f-b614-0a39a6920788%40googlegroups.com
>  
> .
> For more options, visit https://groups.google.com/d/optout 
> .

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/FC7C64A2-2725-4777-95F4-265D3BD3812F%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Site map url with protocol (https)

2016-05-23 Thread Rob Biedenharn
> On 2016-May-23, at 04:31 , Rajkumar Ulaganadhan  wrote:
> 
> Hi All,
> 
> I have used dynamic_sitemaps for sitemap.
> 
> 
> Command to generate xml file "rake sitemap:generate"
> 
> After running this command it is generating this xml files
> 
> 
> 
> http://www.example.com/sitemaps/site.xml
> 
> 
> 
> My Expectation:
> 
> Here i need the protocol as "https" instead of http
> 
> https://www.example.com/sitemaps/site.xml
> 
> 
> How to override the default protocol in sitemap.
> 
> 
> 
> Please give me suggestions
> 
> Thanks in advance.

A quick look at 
https://github.com/lassebunk/dynamic_sitemaps/blob/master/lib/dynamic_sitemaps/sitemap.rb
 

 and 
https://github.com/lassebunk/dynamic_sitemaps/blob/master/lib/dynamic_sitemaps.rb
 

 seems to indicate that this is supported in the config file (config/sitemap.rb 
by default) as:

  protocol "https"

It doesn't get much simpler than that. 

(I've never used this gem, but if you read a lot of Ruby source, these things 
start to become more apparent.)

-Rob

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/5A29435B-AD78-411D-8BE6-D96EF99DB9FE%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Moving a ruby/rails app from one server to another

2016-04-14 Thread Rob Biedenharn

> On 2016-Apr-14, at 14:51 , Vince Laurent  wrote:
> 
> "Have you checked the versions of all the gems (including rails) used
> on the old server and installed those and only those on the new one?"
> 
> using gem list --local
> 
> the old system has 16, the new one 64
> Here is the list of the differences:
> 
> gemoldnew
> 
> actionmailer   (2.3.5)(4.2.5)
> actionpack (2.3.5)(4.2.5)
> activerecord   (2.3.5)(4.2.5)
> activesupport  (2.3.5)(4.2.5)
> acts_as_ferret (0.4.8.2)  (0.5.4)
> devise (1.0.5)na
> fastthread (1.0.7)na
> ferret (0.11.6)  (0.11.8.6)
> jk-ferret  (0.11.8.3)  na
> passenger  (2.2.11)  (5.0.27, 5.0.26)
> rack   (1.0.1)(1.6.4)
> rails  (2.3.5)(4.2.5)
> warden (0.10.2)  na
> will_paginate  (2.3.12)  na
> 
> So... do I get rid of ALL the new gems and try to figure out how to just
> install the old ones?
> 
> -- 
> Posted via http://www.ruby-forum.com/.

There is *a lot* of difference between Rails 2.3 and 4.2 (I know because I've 
recently helped a client do that "upgrade"†).

If your "old" application didn't use `bundler` (aka, does it have a `Gemfile` 
and `Gemfile.lock` in the top directory?), that might be the first tiny upgrade 
to make. Bundler did not exist when Rails 2.3 was current so it's not likely 
present unless someone introduced it.

At the very least, you could update rails to 2.3.18 (the last of its lineage). 
In a Gemfile, that would be:
gem 'rails', '~> 2.3'

The `will_paginate` gem does not support Rails 4 (unless that has changed 
somewhat recently). You might want to look at `kaminari` as a replacement for 
pagination.

-Rob

† it was actually a "full body transplant" rather than an "upgrade in place". 
We started with a bare Rails 4.2.x application and generated models as we went 
along, copying the relevant contents from the old application into the new. 
Same with controllers.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/F6D785CD-3183-421C-AEDA-544547DDF5D4%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] XML API as model in Rails application

2016-04-14 Thread Rob Biedenharn

> On 2016-Apr-14, at 10:56 , alan.kis...@gmail.com wrote:
> 
> Hi all Rails developer, 
> 
> I am newcomer to Rails so I wonder what is best approach to rewrite my 
> current WHOIS search app (PHP) to Rails platform? Currently my idea is to put 
> all XML API cals and calculations in model, is this right? Basically, model 
> would consist of login, getDomainInfo and getContactInfo commands sent to our 
> domain registrar EPP API.
> 
> Thanks, 
> 
> -- 

Sounds like you might want to look at https://github.com/weppos/whois 
 first.

-Rob


-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/6C6A9791-2647-4CC6-B130-78D967DD6AB1%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Inconsistent result of #sum

2016-02-24 Thread Rob Biedenharn

> On 2016-Feb-23, at 20:34 , Mengxi Liao  wrote:
> 
> For some reason the following two queries return different results
> 
> Where there is only one activity record and price is 3.63 and quantity is 
> 16.19, the following codes return results of different rounding.
> 
> sum("CEIL(`activities`.quantity/60) * 60 / 3600 * `activities`.price").to_s
> 
> "58.81"
> 
> sum("CEIL(`activities`.quantity/60) * 60 / 3600 * `activities`.price * 
> 1").to_s
> 
> "58.806" # this is the correct one
> 
> 
> 
> I have checked the raw sql and both return 58.806.
> 
> 
> 
> I believe this is a bug for the sum method.
> 
0 < 16.19 / 60 ≤ 1

so the ceiling of that should be 1

1 * 60.0 / 3600 * 3.63 == 0.0605

so unless you also have a bug in your CEIL() function, I don't see how the 
problem can be in the sum()

what are you really doing?

-Rob


-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/5EB05072-3693-448E-867C-7FC6CDC50405%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] How can I set up a proper getter/setter?

2016-02-09 Thread Rob Biedenharn

> On 2016-Feb-8, at 19:19 , David McDonald  wrote:
> 
> I have a model named, Measurable, that stores many different types of of 
> measurements for different things.  All the measurements can be represented 
> as a decimal, so my value column is of datatype decimal.  My users though 
> wish to view and input these value is either integers or mixed numbers (ex: 
> 31 1/8) as well, depending on the measurable_type.  Right now I'm able to 
> convert the mixed number to a decimal value and store it into my database as 
> a proper decimal. But I'm trying to figure out how to convert it from a 
> decimal value to the mixed number I'm wanting to show the user in my form, so 
> they can make edits if necessary.  Below I have the setter method I made, but 
> my attempts at creating a proper getter haven't work.  I'm not really sure 
> how to go about it.

I think you want to at least consider using Ruby's Rational class to help. 
Here's a pure Ruby example:

class Measurable

  attr_accessor :id, :unit_id, :measurable_type_id, :reliability_id, 
:created_at, :updated_at
  attr_reader :value

  # belongs_to :measurable_type
  def initialize(input)
self.value = input
  end

  def value=(input)
case input
when String
  # Has more than one value
  if (parts = input.split(" ")).size > 1
result = parts.reduce(0) {|whole,part| whole + Rational(part) }
  else
result = input.to_f
  end
when Numeric
  result = input
else
  result = input.to_f
end

@value = result
  end

  def to_s
case self.value
when Rational
  whole = self.value.floor
  "%d %s"%[whole, (self.value - whole).to_s]
else
  self.value.to_s
end
  end
end

irb2.2.4> puts Measurable.new("31 1/8")
31 1/8
#2.2.4 => nil
irb2.2.4> puts Measurable.new("31.125")
31.125
#2.2.4 => nil
irb2.2.4> puts Measurable.new(31.125)
31.125
#2.2.4 => nil

There's also a to_r method to convert types to a Rational if your 
"measurable_type" wanted to convert strictly to a Rational form.

-Rob

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/D38B817D-65E4-4C2A-B17A-E1E9B2A9C808%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Hash table

2015-12-16 Thread Rob Biedenharn

> On 2015-Dec-16, at 17:24 , Scott Eisenberg  wrote:
> 
> Looks to me like you will have an Array of hashes.
> 
> The ruby way something like a single line array select
> 
>  t.select{|tt| a.between?(tt[:min], tt[:max]) && b.between?(tt[:b_min], 
> tt[:b_max])}
> 
> create the array initially with something like
> 
> t = Array.new
> t << {a_min: 1, a_max:10, b_min: 100, b_max: 1000, p1: 1, p2: 2, p3: 3} 
> t << {a_min: 1, a_max:10, b_min: 100, b_max: 1000, p1: 1, p2: 2, p3: 3}  
> 
> (fill in your data)
> 
> you could do t = [{your data}, {your hash data}….]
> 
> If you only want the first value in the array that matches, use t.detect 
> rather than t.select
> 
> It will return either any array of matching hashes or with detect the first 
> one…
> 
> 
> Use the rails console to test all this stuff.  rails c
> 

Or, use the fact that you have a well-defined range for the 'a' and 'b'

TABLE = [
  {a: 40.000..47.95, b: -95.0..-74.01, p1: 12.8, p2: 6.5, p3: 177.82, p4: 
0.9150, p5:   68.62, p6: 0.9020},
  {a: 42.000..47.95, b: -68.0..-59.50, p1: 11.0, p2: 5.8, p3: 185.20, p4: 
0.9377, p5:  -11.80, p6: 0.9538},
  {a: 44.000..47.95, b: -74.2..-68.05, p1: 12.8, p2: 6.5, p3: 157.45, p4: 
0.9194, p5:   37.55, p6: 0.9297},
  {a: 46.000..66.00, b: -59.5..-51.00, p1:  8.8, p2: 3.7, p3: 164.96, p4: 
0.9465, p5: -207.54, p6: 1.0342},
  {a: 47.951..66.00, b: -79.0..-59.55, p1: 12.8, p2: 6.5, p3: 157.45, p4: 
0.9194, p5:   37.55, p6: 0.9297},
  {a: 47.951..66.00, b: -95.0..-79.01, p1: 12.8, p2: 6.5, p3: 177.82, p4: 
0.9150, p5:   68.62, p6: 0.9020},
];
def params(a:, b:)
  TABLE.detect {|h| h[:a].cover?(a) && h[:b].cover?(b) }
end

irb2.2.3> params(a: 45.2, b: -70)
#2.2.3 => {:a=>44.0..47.95, :b=>-74.2..-68.05, :p1=>12.8, :p2=>6.5, 
:p3=>157.45, :p4=>0.9194, :p5=>37.55, :p6=>0.9297}

Obviously build your table as big as you need, but you might have to think 
about a more suitable data structure if this crude linear search through an 
array isn't fast enough.

-Rob

> 
> 
>> On Dec 16, 2015, at 3:55 PM, Suo Huang > > wrote:
>> 
>> Hi all,
>> 
>> I am a newbie in Ruby, and I am having a small question with the hash table. 
>> If anyone could give me some suggestions that would be great!
>> 
>> Considering creating a hash table like this:
>> 
>>  a_Min   a_Max b_Min  b_Max  p1  p2  p3  
>>   p4 p5  p6
>> 40.000   47.95   -95.0   -74.01  12.8 6.5  177.82
>> 0.9150   68.62  0.9020
>> 42.000   47.95   -68.0   -59.50  11.0 5.8  185.20
>> 0.9377   -11.80 0.9538
>> 44.000   47.95   -74.2   -68.05  12.8  6.5 157.45
>> 0.9194   37.55  0.9297
>> 46.000   66.00   -59.5   -51.00  8.8 3.7   164.96
>> 0.9465   -207.541.0342
>> 47.951   66.00   -79.0   -59.55  12.86.5   157.45
>> 0.9194   37.55  0.9297
>> 47.951   66.00   -95.0   -79.01  12.86.5   177.82
>> 0.9150   68.62  0.9020
>> ...
>> 
>> If giving any (a,b), it will fall within the four boundary control values in 
>> the hash table (a_Min, a_Max, b_min, b_Max) and returns its relative 
>> parameters (p1, p2, p3)
>> 
>> I am trying something like this:
>> 
>> def functionXXX(a, b)
>> threshold = XXX  # how to create a 
>> hash table with the above data?
>> for t in threshold do
>>  if (t[:a_Min]<=a && a> then#if there is a smarter way in Ruby for this?
>> return t
>> break
>>  end
>> end
>> end
>> 
>> Would this be the correct way of doing this task in Ruby?
>> 
>> Thanks!
>> 
>> Suo
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ruby on Rails: Talk" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to rubyonrails-talk+unsubscr...@googlegroups.com 
>> .
>> To post to this group, send email to rubyonrails-talk@googlegroups.com 
>> .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/rubyonrails-talk/97f8d9fe-4632-49cd-a5d7-aeb80da4472b%40googlegroups.com
>>  
>> .
>> For more options, visit https://groups.google.com/d/optout 
>> .
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to rubyonrails-talk+unsubscr...@googlegroups.com 

Re: [Rails] Why is admin_signed_in? false even after logging in as admin?

2015-12-11 Thread Rob Biedenharn

> On 2015-Dec-11, at 14:58 , Jason Hsu, Ruby on High Speed Rails 
> <jhsu802...@gmail.com> wrote:
> 
> Thanks.  Yes, this was the problem.  Now I understand that this is the proper 
> procedure for logging in for functional tests.
> 
> This raises another question: Given my use of if statements in my def create 
> function, is there any point to using before_filter or before_action in the 
> controller?  The before_filter/before_action statement doesn't replace the 
> need for those if statements.

You could have a before_action that was something like:

before_action :require_admin, except: [ :index, :show ]

def require_admin
  unless admin_signed_in?
redirect_to not_authorized_url
  end
end


> 
> On Friday, December 11, 2015 at 12:44:41 PM UTC-6, Rob Biedenharn wrote:
> 
> > On 2015-Dec-11, at 13:12 , Jason Hsu, Ruby on High Speed Rails 
> > <jhsu8...@gmail.com > wrote: 
> > 
> > The admin_signed_in? method comes from the Devise gem. 
> 
> Are you using the :admin scope to do the login? 
> 
> I.e., somewhere in your login_as helper there should be something like? 
> 
> sign_in :admin, some_user_who_is_admin 
> 
> 
> -Rob
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to rubyonrails-talk+unsubscr...@googlegroups.com 
> <mailto:rubyonrails-talk+unsubscr...@googlegroups.com>.
> To post to this group, send email to rubyonrails-talk@googlegroups.com 
> <mailto:rubyonrails-talk@googlegroups.com>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rubyonrails-talk/5c47366b-2641-469b-a5de-4981e95e2fcf%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/rubyonrails-talk/5c47366b-2641-469b-a5de-4981e95e2fcf%40googlegroups.com?utm_medium=email_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/BB5F7462-B214-47AD-A3A9-911C0E21B7E0%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Re: Why is admin_signed_in? false even after logging in as admin?

2015-12-11 Thread Rob Biedenharn

> On 2015-Dec-11, at 13:12 , Jason Hsu, Ruby on High Speed Rails 
>  wrote:
> 
> The admin_signed_in? method comes from the Devise gem.

Are you using the :admin scope to do the login?

I.e., somewhere in your login_as helper there should be something like?

sign_in :admin, some_user_who_is_admin


-Rob

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/4F9F7996-CDF5-4D8D-9D89-49550DB63CA8%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Rails-4.2.1 WebRick SSLEnable

2015-09-21 Thread Rob Biedenharn

> On 2015-Sep-21, at 15:59 , byrnejb  wrote:
> 
> in
> /usr/lib64/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/server.rb
> 
> at line 124 we see:
> 
> url = "#{options[:SSLEnable] ? 'https' : 
> 'http'}://#{options[:Host]}:#{options[:Port]}"
> 
> My question is:  How does one pass the option key
> :SSLEnable
> 
> 
> to webrick using $ rails server in development mode (or production mode for 
> that matter)?

Here's how one person did (does) it:

https://gist.github.com/mindscratch/5028880 


After requiring the needed prerequisites, he overrides (redefines) the 
Rails::Server#default_options

-Rob

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/E65105C0-A183-448B-8596-373FF219E8D5%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Hi, I just started learning about an hour a go and already need help. :-)

2015-09-11 Thread Rob Biedenharn

> On 2015-Sep-11, at 11:00 , Nick Savage  wrote:
> 
> Okay I started with Learn the hard way with ruby.
> My code is below and below each code is my question.
> I guess I do not understand the identifiers because when I do them in my head 
> they dont add up.
> 
> Any help would be appreciative and the way I learn I can not move on till I 
> know.

This is just barely a Ruby issue. Most operator precedence is the same as you'd 
expect just from math:
http://ruby-doc.org/core-2.2.3/doc/syntax/precedence_rdoc.html 



> 
> puts "I will now count my chickens:'"
> puts "Hens #{25 + 30 / 6}"
> #how does that equal 30?

25 + (30/6)
25 +5
30

> puts "Roosters #{100 - 25 * 3 % 4}"
> #How does this equal 97

100 - (25 * 3 % 4)
100 - ((25 * 3) % 4)  # same precedence, do them left-to-right
100 - (75   % 4)
100 - ( 3  )  # 75 % 4 is the remainder after 75/4
100 - 3
97

> 
> puts "Now I will count the eggs:"
> 
> puts 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6
> #How does this equal 7, is it because it is 6.5 and it rounds up.

Here you have to add a fact (behavior) common to many programming languages: 
"integer division truncates to an integer"

3 + 2 + 1 - 5 + (4%2) - (1/4) + 6
3 + 2 + 1 - 5 + ( 0 ) - ( 0 ) + 6   # then do the + and - left-to-right
  5   + 1 - 5 + ( 0 ) - ( 0 ) + 6
  6   - 5 + ( 0 ) - ( 0 ) + 6
  1   + ( 0 ) - ( 0 ) + 6
  1   - ( 0 ) + 6
  1   + 6
  7

Very simple. Perhaps you're over-thinking it?

-Rob

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/98289E25-4163-4815-8F86-855810FA6725%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] DB Code Optimization

2015-09-09 Thread Rob Biedenharn
> On 2015-Sep-9, at 11:19 , John Lahr  wrote:
> 
> I'm not sure I'm reading this right, but if you're looking for the answers to 
> the questions asked by a specific user wouldn't it be
> 
> @user = User.find(params[:id]
> @user.questions = the questions the user asked
> @user.questions.answers = the answers to the questions the user asked.
> 
> THere's something troubling to me about your model set up but I can't think 
> of what it is.
> 
> On Wednesday, September 9, 2015 at 4:18:46 AM UTC-7, Ruby-Forum.com User 
> wrote:
> Hi, I have the following tables: 
> 
> - users 
> -- id 
> -- username 
> 
> 
> - questions 
> -- id 
> -- asker_id 
> -- question_text 

Even though you have the column as "asker_id" rather than the conventional 
"user_id", your use of the foreign_key: on the belongs_to compensates.

> 
> - answers 
> -- id 
> -- answerer_id 
> -- answer_text 

Again with the un-conventional foreign_key, but what's missing is a 
"question_id" to go along with your Answer model's belongs_to :question

> 
> 
> And I wanna make a query to get all questions, with the username who 
> asked, and all question answers. I made the code but please tell me if 
> is a good practice: 
> 
>  class User < ActiveRecord::Base 
> has_many :questions 

you need to declare the foreign_key here, too (foreign_key: :asker_id)

Also, you can add:

has_many :answers, through: :questions

has_many :responses, class_name: "Answer", foreign_key: :answerer_id


> end 
> class Question < ActiveRecord::Base 
> validates :question_text, presence: true 
> belongs_to :user, foreign_key: "asker_id" 
> has_many :answers 
> end 
> 
> class Answer < ActiveRecord::Base 
> belongs_to :question 
> belongs_to :user, foreign_key: "answerer_id" 

def asker
  self.question.try(:user)
end

> end 
> Controller: 
> @questions = Question.joins(:user).joins('LEFT JOIN answers on 
> answers.question_id = questions.id ').order(id: 
> 'desc').group(:id) 
> A user can: 
> 
> Have more questions 
> 
> A question can: 
> 
> Have more answers 

Then you can have any of the following:

@user = User.includes(questions: :answers).find_by username: "foo"
@user.questions # for all this user's questions
@user.answers   # for all the answers to all the questions asked by this user
@user.responses # for the answers that this user gave in response to a question

@questions = Question.includes(:user, :answers).order(id: :desc).all

@answer = Answer.includes(:user, :question).find_by id: some_id
@answer.user# the one who gave the answer
@answer.question# the question
@answer.asker   # the one who asked the question

That should get you going.

-Rob

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/50F865F4-CDC4-46CE-A62D-DB044D9689C4%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Method each strange behavior with AR association

2015-09-04 Thread Rob Biedenharn
> On 2015-Sep-4, at 15:56 , Николай Спелый  wrote:
> 
> Great !
> I already try write this logic but it not works. But when i copy-paste your 
> variant it's work.
> So difference is in formating code, i write in one line, you write in three 
> lines.
> That's nice for resolving problem, but why it's works in divided style of 
> ruby and not works in one-line style ?
> My one-line is <%= Chat.find_by(id: 6).chatusers.each { |chat_user| 
> chat_user.user } %> which about i told.

So you have:

<%= something %>

which ERB interprets as call .to_s on the result of evaluating something and 
add that to the output (possibly after making it HTML-safe depending on your 
Ruby on Rail version)

Therefore, what is the value of 

Chat.find_by(id: 6).chatusers.each { |chat_user| chat_user.user }

Well, that's just something.each {|…| … } which has the value of something. In 
your case, the same as if you just had:

Chat.find_by(id: 6).chatusers

This is probably some ActiveRecord proxy for the association. The default .to_s 
is very likely similar to .inspect and looks something like:

#

So plop that into your HTML and a browser sees the <…> as an unknown element 
and does nothing so you're left with:

#

in your page. Does that make sense to you?

-Rob

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/66CBE3C5-E5B9-46F0-A029-0B9AD6828BBC%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Andriod tablets

2015-08-26 Thread Rob Biedenharn

 On 2015-Aug-26, at 14:26 , Jason Weber unclejj4...@gmail.com wrote:
 
 hello, im new to learning ruby, does anyone know if you can use a tablet to 
 run ruby or do you need a computer to run it?
 
 --

Check out http://ruboto.org/ http://ruboto.org/ if you want to run Ruby on 
Android.

I don't know how much it helps or hinders the learning process however.

-Rob


-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/A22B0EE1-0B6F-4F64-97D4-342B7DF1CDB0%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] how to timeout a session in rails 2.3.9

2015-06-03 Thread Rob Biedenharn
At the VERY least, you should upgrade to Rails 2.3.18 as there were security 
fixes in every one of those 9 updates (some of them quite serious!).

Speaking as someone who also has a client with many lines of code running in a 
Rails 2.3.18 framework-based application, you can really upgrade (a little bit).

-Rob


On 2015-Jun-3, at 12:17 , skrite sh...@skrite.net wrote:

 i cannot really upgrade. I would love too, but i have a bazillion lines of 
 code for this version running.
 you were right. terminology was wrong expire_after not expires..
 
 tested and working now, thanks very much !
 
 sk
 
 On Wednesday, June 3, 2015 at 9:20:52 AM UTC-5, skrite wrote:
 I am running a rails 2.3.9 app and I cannot seem to make the session expire.
 
 I have tried the :expires_after = in the environment.rb and it works in 
 webrick, but crashes on nginx with passenger.
 
 Is there a way in the application controller or somewhere else that I can set 
 a session variable to timeout after a certain amount of time ?
 
 thanks for any tips
 
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/915430a1-3b52-4a6e-abf6-0e8f4aa6e10c%40googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/2BD9AD74-E540-4DAC-8E92-6369A81DC773%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Sort hash in model

2015-05-29 Thread Rob Biedenharn

On 2015-May-29, at 09:24 , Gm javapla...@gmail.com wrote:

 Hi, I have this hash:
 
 hash = { 4049=[4133, 100], 5814=[4075, 84], 382543=[4064, 74], 
 382544=[4065, 99], 382545=[4066, 75] }
 
 I need to sort (DESC) this hash by the second item of array.
 Example: 100, 84, 74, 99, 75
 
 How can I solve this problem ? I'm using sort method but can't work it out.
 
 Thanks.

Well, assuming that you know a Hash isn't really sortable and you'll end up 
with an Array (of Arrays)...

irb2.2.2 hash = { 4049=[4133, 100], 5814=[4075, 84], 382543=[4064, 74], 
382544=[4065, 99], 382545=[4066, 75] }
#2.2.2 = {4049=[4133, 100], 5814=[4075, 84], 382543=[4064, 74], 
382544=[4065, 99], 382545=[4066, 75]}
irb2.2.2 hash.sort_by {|k,v| v[1]}
#2.2.2 = [[382543, [4064, 74]], [382545, [4066, 75]], [5814, [4075, 84]], 
[382544, [4065, 99]], [4049, [4133, 100]]]
irb2.2.2 hash.sort_by {|k,v| v[1]}.reverse
#2.2.2 = [[4049, [4133, 100]], [382544, [4065, 99]], [5814, [4075, 84]], 
[382545, [4066, 75]], [382543, [4064, 74]]]
irb2.2.2 hash.sort_by {|k,v| -v[1]}
#2.2.2 = [[4049, [4133, 100]], [382544, [4065, 99]], [5814, [4075, 84]], 
[382545, [4066, 75]], [382543, [4064, 74]]]


You really want Hash#sort_by

-Rob

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/97435771-D2FE-432F-8B65-371DF693B404%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Generate image from base64

2015-05-13 Thread Rob Biedenharn
You might be able to look at https://github.com/madrobby/spark_pr 

which can be extended with:

SparkCanvas.class_eval do
  def to_uri
require 'base64'
# doesn't attempt to respect some limits noted in RFC 2397 since the data:
# url is supposed to be 'short' (1k), but the meaning of that word has 
changed
# a bit since 1998.
# Modern browsers allow 4k-32k or more According to 
http://dataurl.net/#about
%{data:image/png;base64,#{Base64.encode64(to_png).gsub(\n,'')}}
  end
end

and work it backwards.

-Rob

On 2015-May-13, at 19:03 , Walter Lee Davis wa...@wdstudio.com wrote:

 I would start here: 
 http://ruby-doc.org/stdlib-2.2.2/libdoc/base64/rdoc/Base64.html#method-i-decode64
 
 Save the result to a file on disk.
 
 Walter
 
 On May 13, 2015, at 6:18 PM, Gm javapla...@gmail.com wrote:
 
 Hi,
 
 I have the following base64:
 
 data:image/png;base64,iVBORw0KGgoNSUhEUgAAAXMAAAB/CAIAAACSbbUKAAAKsGlDQ1BJQ0MgUHJvZmlsZQAASA2tlndUk8kaxuf70hstIRQpoXekV+k1FOlVVEISSCgxBIKIqKgsruCKIiICFtCVpuCq1LUgFkRdBBv2BVlU1OtiQVRU7he4ZPece/e/O+fMzC/v92TKOzPnPACQK1lCYTosB0CGIFsU7ufJiI2LZ+B+BxDAAAKgA0UWO0voERoaBP6xfLyLqJFyy0wy1j/K/vcHeQ43iw0AFIp8TuJksTMQPoXUArZQlA0AygaJ667OFko4FmGaCFkgwpJ5aCnzXCDhpHkun9NEhnshmgYA8GQWS5QCAOkUEmfksFOQcUi3EbYQcPgCAMhohF3ZPBYHYW+ETTMyVklYiLBh0t/GSfkbs1hJ0jFZrBQpz+8F+ScysTc/S5jOWjP34//ZZKSLkXzNFQ2kJWelRQQiPR7JWS6b5ROxwDwuU3Jmc3Fhtmf4AvOzmZELzBP7Ry2wOC3KY4HTVgVK9YKkpSELcXaWF5L7+THzeJExC8zhevsssGhVuFSflRMhjefxvJYuaFJZAZLznlsbS4TQf5ib7iedV5gdKl2nIH2pdC/JIl+phpv1136zeZH+C+NkiyKlmmS+L3MhzhP5S+PC9Lk7PbcGkThcmgeuIEqaQw7LW5pbwAfBgAXY2dxc5A4B4LVKuEbET+FlMzyQW881ZTAFbHNThpWFpS2QvCGJBoD39Lm3AdGv/hXL7AHAsRg5L8n1ZUhUALB0AOh6BgD1418xnXfI8e4A4MwgWyzKmddJrivyMolAFtCACtAAOsAQmAErYAecgTvwAQEgBESCOLACsAEPZAARWA3ywUZQBErADrAbVIED4BBoAMfACdABToPz4DK4BgbBHfAQjIBx8ApMgo9gBoIgHESBqJAKpAnpQSaQFeQAuUI+UBAUDsVBiVAKJIDEUD60GSqByqAqqBZqhH6BuqDzUD80BN2HRqEJ6B
 
 Is there a way to generate a PNG or JPG from this code using rails ?
 
 Thanks.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/adca2adf-95a0-45ed-a472-25e89ffd79b4%40googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/F09CA941-9375-4221-94FB-641400541C67%40wdstudio.com.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CF5408C0-EC23-4874-A8DD-02C049AB3264%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Successfully installed rails-4.2.1 ERROR: Could not find a valid gem '4.2.1' (= 0) in any repo

2015-04-29 Thread Rob Biedenharn

On 2015-Apr-29, at 11:24 , Bailey J kidbay...@gmail.com wrote:

 Thanks that helps.  So it was probably just the way I passed the command...
 
 This is what I typed sudo gem install rails 4.2.1 --no-ri --no-rdoc, does 
 that look funny?

You need to have -v in front of the version:

sudo gem install rails -v 4.2.1 --no-ri --no-rdoc

Other version specifiers might require quotes to keep the shell from attempting 
input/output redirection. E.g.:

sudo gem install rails -v '= 4.2.1' --no-ri --no-rdoc


-Rob

 
 Should I be concerned about the contents of this error message Could not 
 find a valid gem or is it simply nothing more than what you just said?
 
 What I wanted to do was pass the command with head in it but I don't know the 
 syntax for that and I couldn't find a reference to it that quickly.  Does 
 anyone know the proper way to pass the command for get head?
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/f99d7296-5b96-4b4b-8fa4-c02251efebcc%40googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/F645F1C9-F24E-4C2C-A1B1-90477CDBF1E1%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Re: Successfully installed rails-4.2.1 ERROR: Could not find a valid gem '4.2.1' (= 0) in any repo

2015-04-29 Thread Rob Biedenharn

On 2015-Apr-29, at 13:30 , Bailey J kidbay...@gmail.com wrote:

 Thanks Rob,
 
 At this point I got the version I wanted even with the incorrect syntax, I 
 can just leave it as it is?
 
 -Bailey

Yes, of course, the response was basically to point out where your command had 
done something that you hadn't realized that you'd requested. More of a lesson 
for the next time when you really might need to request a version that's not 
the default that would be installed.

-Rob

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/128EC3A0-3E3E-44D7-80D3-F907F96411EE%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Replace find_by_sql with find (Rails 2.3)

2015-04-27 Thread Rob Biedenharn

On 2015-Apr-27, at 13:40 , Norm Scherer normsche...@earthlink.net wrote:

 It does have named scopes but I am not sure what that would bring to the 
 table.  How would one do it using named scopes?
 
 Norm
 
 On 04/25/2015 01:52 PM, Walter Lee Davis wrote:
 I can't recall, does Rails 2.3 have named scopes? You may be able to do this 
 with one of those. It's been quite a while since I worked in 2.3.
 
 Walter
 
 On Apr 25, 2015, at 3:06 PM, Norm Scherer normsche...@earthlink.net wrote:
 
 I have an app running Rails 2.3 with Ruby 1.8.7.   Upgrading is not in the 
 cards for a while.

I feel your pain.

   I am trying to make it database agnostic so I want to eliminate the use 
 of find_by_sql.  I have got it down to only one find left but I have not 
 been able to figure out how to do this by a find.
 
 I have two tables:
 Reservation belongs_to :space
   int space_id
   date startdate
   date enddate
   and a bunch of other stuff
 
 Space - has many reservations
   containing a bunch of stuff about spaces
 
 I want to fetch the spaces which are not used by a reservation meeting 
 certain conditions.
 The current find is:
 all_spaces = find_by_sql(SELECT * FROM spaces
 WHERE id NOT IN (SELECT space_id FROM 
 reservations
  WHERE 
 enddate  \'#{start_dt}\'
  AND 
 startdate  \'#{end_dt}\')
 )
 Is there a way I can just use a Space.all ...?
 
 Norm

I think that this named_scope should work though I'm not sure that it can be 
considered database agnostic. (Walter's might be close, but not until you have 
ARel to use.

Reservation.class_eval do
  belongs_to :space
end

Space.class_eval do
  has_many :reservations
  named_scope :available_for, lambda{|start_dt, end_dt|
{ :conditions = [[id NOT IN (SELECT space_id FROM reservations,
   WHERE reservations.enddate  ?,
   AND reservations.startdate  ?),
  ].join( ), start_dt, end_dt] } }
end

Space.available_for(Date.new(2015,5,11), Date.new(2015,5,15))



The alternative would be to have a method on Reservation that returned the 
space_ids:

Reservation.class_eval do
  belongs_to :space
  def self.for_space_ids_during(start_dt, end_dt)
find(:all, {
   :conditions = [enddate  ? AND startdate  ?,
   start_dt, end_dt],
   :select = :space_id,
 }).map(:space_id)
  end
end

Space.class_eval do
  has_many :reservations
  named_scope :except, lambda{|ids|
{ :conditions = [id NOT IN (?),
  Reservation.for_space_ids_during(start_dt, end_dt)] } }
end



Or even making that an association extension:

Space.class_eval do
  has_many :reservations do
def available_for(start_dt, end_dt)
  reject {|rsv| rsv.enddate  start_dt  rsv.startdate  end_dt }
end
  end
end

But this last bit is certainly the most inefficient and least visually similar 
to what it sounds like you'd like to have in a modern version of Rails.

In all cases, know that I haven't run this code so I only suggest that it might 
work. ;-)

-Rob

 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/553BE59C.9040001%40earthlink.net.
 For more options, visit https://groups.google.com/d/optout.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/553E747A.20505%40earthlink.net.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/56AC09C4-1619-4826-BA7B-A28C413F94D9%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Rails guides - No route matches [POST] /articles/new

2015-02-05 Thread Rob Biedenharn

On 2015-Feb-5, at 13:49 , Greg Bressler li...@ruby-forum.com wrote:

 I was working my way through Rails Guides getting started tutorial
 (http://guides.rubyonrails.org/getting_started.html).  Everything was
 going well until the end of 5.2 when I was set to make a blog post.  Any
 help that could be provided would be greatly appreciated.
 
 
 Here's the trace:
 
 No route matches [POST] /articles/new

Presumably, you have: new_article_path in your form_for, but you ought to have: 
articles_path

See the routes listing you have below that only has GET for the /articles/new 
path and the path which routes to articles#create is a POST to /articles (same 
as the GET uses for articles#index)

-Rob

 
 Rails.root: /home/gregb/workspace/blog
 
 
 Application Trace | Framework Trace | Full Trace
 actionpack (4.1.8)
 lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
 actionpack (4.1.8)
 lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
 railties (4.1.8) lib/rails/rack/logger.rb:38:in `call_app'
 railties (4.1.8) lib/rails/rack/logger.rb:20:in `block in call'
 activesupport (4.1.8) lib/active_support/tagged_logging.rb:68:in `block
 in tagged'
 activesupport (4.1.8) lib/active_support/tagged_logging.rb:26:in
 `tagged'
 activesupport (4.1.8) lib/active_support/tagged_logging.rb:68:in
 `tagged'
 railties (4.1.8) lib/rails/rack/logger.rb:20:in `call'
 actionpack (4.1.8) lib/action_dispatch/middleware/request_id.rb:21:in
 `call'
 rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
 rack (1.5.2) lib/rack/runtime.rb:17:in `call'
 activesupport (4.1.8)
 lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
 rack (1.5.2) lib/rack/lock.rb:17:in `call'
 actionpack (4.1.8) lib/action_dispatch/middleware/static.rb:84:in `call'
 rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
 railties (4.1.8) lib/rails/engine.rb:514:in `call'
 railties (4.1.8) lib/rails/application.rb:144:in `call'
 rack (1.5.2) lib/rack/lock.rb:17:in `call'
 rack (1.5.2) lib/rack/content_length.rb:14:in `call'
 rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
 /home/gregb/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:138:in
 `service'
 /home/gregb/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:94:in
 `run'
 /home/gregb/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/server.rb:294:in
 `block in start_thread'
 Routes
 
 Routes match in priority from top to bottom
 
 Helper  HTTP Verb  Path  Controller#Action
 Path / Url
 welcome_index_path  GET  /welcome/index(.:format)  welcome#index
 root_path  GET  /  welcome#index
 articles_path  GET  /articles(.:format)  articles#index
 POST  /articles(.:format)  articles#create
 new_article_path  GET  /articles/new(.:format)  articles#new
 edit_article_path  GET  /articles/:id/edit(.:format)  articles#edit
 article_path  GET  /articles/:id(.:format)  articles#show
 PATCH  /articles/:id(.:format)  articles#update
 PUT  /articles/:id(.:format)  articles#update
 DELETE  /articles/:id(.:format)  articles#destroy
 
 -- 
 Posted via http://www.ruby-forum.com/.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/03e12fb45a457bb7b6898c1ea5f18a19%40ruby-forum.com.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/58C0215C-064C-42A5-8E5B-1DF258991006%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Splitting documents in heroku

2015-02-04 Thread Rob Biedenharn

On 2015-Feb-4, at 11:40 , Chirag Aggarwal chi6...@gmail.com wrote:

 Hello,
 
 I am working on a slide sharing application which lets people upload 
 presentations and pdfs and shows them in the browser. The website is hosted 
 on heroku and slides are being uploaded to AWS S3 using CarrierWave gem.
 
 Link: SlideSquare
 
 http://slidesquare.herokuapp.com
 
 Problem: I am using Google Docs viewer to view presentations online right 
 now, which fails to display .odp and .ppt, .pptx and related file formats. I 
 have come across DocSplit Gem ( https://github.com/documentcloud/docsplit ) 
 to extract images from ppt, pptx but unfortunately I have failed to implement 
 it because Heroku does not allow write access to its system, and images can 
 hence not be extracted in production.

Actually, you can write to a temporary directory on Heroku. You just can't rely 
on that storage being available past the end of the request. I've relied on 
this behavior for building PDFs and then delivering them to the browser with a 
Rails send_file

Depending on whether you pull images from PPT only on demand, this might be 
enough for you.

-Rob

 
 Please describe a suitable way to resolve the problem, while using Heroku. If 
 not so, please provide good alternatives.
 
 The website is live here: http://slidesquare.herokuapp.com
 Source code: http: https://github.com/chi6rag/SlideSquare
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/ce239e3b-0114-4004-9479-08354591e709%40googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/2F5547E5-AE9D-4D40-9A72-5BFF01EEEFE1%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Intermittent NoMethodError: undefined method `url_for' for nil:NilClass

2015-01-23 Thread Rob Biedenharn

On 2015-Jan-23, at 12:08 , mikej mikejerem...@gmail.com wrote:

 I am receiving the error above intermittently, rarely on the same url twice.
 
 Backtrace below.  Any ideas how to debug this gratefully received.
 
 Many thanks,
 
 Mike
 
 /gems/actionpack-3.2.21/lib/action_dispatch/routing/url_for.rb:148 in 
 url_for
 /gems/actionpack-3.2.21/lib/action_view/helpers/url_helper.rb:107 in url_for
 /gems/actionpack-3.2.21/lib/action_dispatch/routing/route_set.rb:216 in 
 some_path
 /app/views/authenticate/users/_user.html.erb:7 in 
 _app_views_authenticate_users__user_html_erb___1243416502719325842_58946580

Look at line 7 in your file app/views/authenticate/users/_user.html.erb, or ...

 /gems/actionpack-3.2.21/lib/action_view/template.rb:145 in block in render
 /gems/activesupport-3.2.21/lib/active_support/notifications.rb:125 in 
 instrument
 /gems/actionpack-3.2.21/lib/action_view/template.rb:143 in render
 /gems/actionpack-3.2.21/lib/action_view/renderer/partial_renderer.rb:351 in 
 block in collection_with_template
 /gems/actionpack-3.2.21/lib/action_view/renderer/partial_renderer.rb:348 in 
 each
 /gems/actionpack-3.2.21/lib/action_view/renderer/partial_renderer.rb:348 in 
 collection_with_template
 /gems/actionpack-3.2.21/lib/action_view/renderer/partial_renderer.rb:250 in 
 render_collection
 /gems/actionpack-3.2.21/lib/action_view/renderer/partial_renderer.rb:234 in 
 block in render
 /gems/actionpack-3.2.21/lib/action_view/renderer/abstract_renderer.rb:38 in 
 block in instrument
 /gems/activesupport-3.2.21/lib/active_support/notifications.rb:123 in block 
 in instrument
 /gems/activesupport-3.2.21/lib/active_support/notifications/instrumenter.rb:20
  in instrument
 /gems/activesupport-3.2.21/lib/active_support/notifications.rb:123 in 
 instrument
 /gems/actionpack-3.2.21/lib/action_view/renderer/abstract_renderer.rb:38 in 
 instrument
 /gems/actionpack-3.2.21/lib/action_view/renderer/partial_renderer.rb:233 in 
 render
 /gems/actionpack-3.2.21/lib/action_view/renderer/renderer.rb:41 in 
 render_partial
 /gems/actionpack-3.2.21/lib/action_view/renderer/renderer.rb:15 in render
 /gems/actionpack-3.2.21/lib/action_view/helpers/rendering_helper.rb:24 in 
 render
 /gems/haml-4.0.5/lib/haml/helpers/action_view_mods.rb:12 in render_with_haml
 /app/views/authenticate/users/index.html.erb:8 in 
 _app_views_authenticate_users_index_html_erb___2833816390172654754_51912340

line 8 of app/views/authenticate/users/index.html.erb

for something that builds a URL like a link_to

Good Luck!

-Rob

 /gems/actionpack-3.2.21/lib/action_view/template.rb:145 in block in render
 /gems/activesupport-3.2.21/lib/active_support/notifications.rb:125 in 
 instrument
 /gems/actionpack-3.2.21/lib/action_view/template.rb:143 in render
 /gems/actionpack-3.2.21/lib/action_view/renderer/template_renderer.rb:47 in 
 block (2 levels) in render_template
 /gems/actionpack-3.2.21/lib/action_view/renderer/abstract_renderer.rb:38 in 
 block in instrument
 /gems/activesupport-3.2.21/lib/active_support/notifications.rb:123 in block 
 in instrument
 /gems/activesupport-3.2.21/lib/active_support/notifications/instrumenter.rb:20
  in instrument
 /gems/activesupport-3.2.21/lib/active_support/notifications.rb:123 in 
 instrument
 /gems/actionpack-3.2.21/lib/action_view/renderer/abstract_renderer.rb:38 in 
 instrument
 /gems/actionpack-3.2.21/lib/action_view/renderer/template_renderer.rb:46 in 
 block in render_template
 /gems/actionpack-3.2.21/lib/action_view/renderer/template_renderer.rb:54 in 
 render_with_layout
 /gems/actionpack-3.2.21/lib/action_view/renderer/template_renderer.rb:45 in 
 render_template
 /gems/actionpack-3.2.21/lib/action_view/renderer/template_renderer.rb:18 in 
 render
 /gems/actionpack-3.2.21/lib/action_view/renderer/renderer.rb:36 in 
 render_template
 /gems/actionpack-3.2.21/lib/action_view/renderer/renderer.rb:17 in render
 /gems/actionpack-3.2.21/lib/abstract_controller/rendering.rb:110 in 
 _render_template
 /gems/actionpack-3.2.21/lib/action_controller/metal/streaming.rb:225 in 
 _render_template
 /gems/actionpack-3.2.21/lib/abstract_controller/rendering.rb:103 in 
 render_to_body
 /gems/actionpack-3.2.21/lib/action_controller/metal/renderers.rb:28 in 
 render_to_body
 /gems/actionpack-3.2.21/lib/action_controller/metal/compatibility.rb:50 in 
 render_to_body
 /gems/actionpack-3.2.21/lib/abstract_controller/rendering.rb:88 in render
 /gems/actionpack-3.2.21/lib/action_controller/metal/rendering.rb:16 in 
 render
 /gems/actionpack-3.2.21/lib/action_controller/metal/instrumentation.rb:40 in 
 block (2 levels) in render
 /gems/activesupport-3.2.21/lib/active_support/core_ext/benchmark.rb:5 in 
 block in ms
 /home/wlegalr/.rbenv/versions/1.9.3-p550/lib/ruby/1.9.1/benchmark.rb:295 in 
 realtime
 /gems/activesupport-3.2.21/lib/active_support/core_ext/benchmark.rb:5 in ms
 /gems/actionpack-3.2.21/lib/action_controller/metal/instrumentation.rb:40 in 
 block in render
 

Re: [Rails] `rails s -e production` loads development database not production

2015-01-21 Thread Rob Biedenharn

On 2015-Jan-21, at 16:13 , Mads Ohm Larsen li...@ruby-forum.com wrote:

 Jiajia Wang wrote in post #1166961:
 I'm running into a very weird rails server problem.
 
 I started a rails application in production mode with `rails s -e
 produciton` and got some db errors when visiting the site.

Did you cut-n-paste that command?
Because you have misspelt produciton (swapped i and t)

-Rob

 Have you tried with
 
 $ RAILS_ENV=production bundle exec rails s
 
 instead? Does this yield different results?
 
 -- 
 Posted via http://www.ruby-forum.com/.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/e52704beaba5557a2a789579dd8dd2f4%40ruby-forum.com.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/62E36563-AF2D-4C89-BD61-654B3240D752%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Mail notifications to self Net::SMTPAuthenticationError

2014-11-18 Thread Rob Biedenharn
Take a look at:
https://support.google.com/accounts/answer/185833?hl=en

-Rob

On 2014-Nov-18, at 15:22 , bradford li bradfor...@gmail.com wrote:

 I am trying to set up a mailer to send myself notification methods. I am 
 currently trying to get the mailer to send myself a simple message when I go 
 to the URL `localhost:3000/send_mail`
 
 I am currently getting this error:
 
 Net::SMTPAuthenticationError in HomeController#send_mail
 534-5.7.9 Application-specific password required
 
 development.rb:
 
   config.action_mailer.raise_delivery_errors = true
   host = 'localhost:3000'
   config.action_mailer.default_url_options = { host: host }
   config.action_mailer.delivery_method = :smtp
   config.action_mailer.smtp_settings = {
 address:  'smtp.gmail.com',
 port: 587,
 domain:   'gmail.com',
 user_name:'myem...@gmail.com',
 password: 'mypwd',
 authentication:   'plain',
 enable_starttls_auto: true  }
 
 routes:
 
match '/send_mail', to: home#send_mail, via: get
 
 home controller:
 
 class HomeController  ApplicationController
   def index
   end
 
   def send_mail
   ActionMailer::Base.mail(:from = m...@example.com, :to = 
 myem...@gmail.com, :subject = Contact request, :body = 
 test).deliver_now
 render nothing: true
   end
 end
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/904d2d19-b058-4150-ba98-06279ce8c966%40googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/3B82D324-8DDF-4589-BD19-34B857AE00A4%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] undefined method `symbolize_keys' for

2014-11-10 Thread Rob Biedenharn

On 2014-Nov-10, at 16:17 , Dave Castellano li...@ruby-forum.com wrote:

 Dave Aronson wrote in post #1162130:
 
 
 Try fixing the src= bit.  That's HTML, not Ruby.
 
 %= link_to(image_tag asset_path(#{subject.icon} + '.png'), 
 index_books_path(:subject_id = subject.id)) % still throws same error.

Try it without attempting to elide the parentheses around the single argument 
of image_tag:

%= link_to(image_tag(
  asset_path(#{subject.icon} + '.png')
), 
index_books_path(:subject_id = subject.id)
   ) %

Your version is almost certainly being interpreted as if you had put:

%= link_to(image_tag(asset_path(#{subject.icon} + '.png'), 
  index_books_path(:subject_id = subject.id)
 )
   ) %

 %= image_tag asset_path(#{subject.icon} + '.png') % works fine so I 
 am assuming its the link_to and not the image_tag.
 
 Dave
 
 -- 
 Posted via http://www.ruby-forum.com/.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/a794f86cd2dbf057d8bca2e0fae6993d%40ruby-forum.com.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/0255AE79-5954-4835-9EB9-48EC49F55265%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Help with small rails app

2014-10-21 Thread Rob Biedenharn

On 2014-Oct-21, at 16:54 , Dominic Monaco jarvis...@gmail.com wrote:

 Hey guys I'm completely lost at this point I'm trying to make a simple app 
 that takes an input in the form of a string (City, State) and sends that 
 string to the google_places gem to do spot_by_query(gas station near #{enter 
 value from input})
 
 Then I need the 1st 10 results and be able to print out their names.  I have 
 become completely lost in my attempts and was looking for some advice. 
 
 Here is my controller
 class LocationsController  ApplicationController
   before_action :set_location, only: [:show, :edit, :update, :destroy]
 
   # GET /locations
   # GET /locations.json
   def index
 @location = Location.new
   end
 
   # GET /locations/1
   # GET /locations/1.json
   def show
 
   end
 
   # GET /locations/new
   def new
 
   end
 
   # POST /locations
   # POST /locations.json
   def create
 @client = GooglePlaces::Client.new('')
 
 @shops = @client.spots_by_query('coffee near 
 #{@location(params[:address])}')
 @result = JSON.parse(@shops[1])
 # @location.find_closest_shops(@location.params[:address])
   end
 
   private
 # Never trust parameters from the scary internet, only allow the white 
 list through.
 def location_params
   params.require(:location).permit(:address)
 end
 end
 
 
 Here is the input form
 %= form_for @location do |f| %
   %= f.label :address %
   %= f.text_field :address, :placeholder = City State %
   br
   %= f.submit Find Coffee! %
 % end %
 
 Here is the output form (this is where I'm lost)
 %= print #{@result['name']} %
 

Well, after making a few assumptions:
you are going to a URL that gets routed to the index action like /locations
the form posts to /locations

In your create action, you probably need to replace:
 @shops = @client.spots_by_query('coffee near 
 #{@location(params[:address])}')
With:
 @shops = @client.spots_by_query(coffee near 
 #{location_params[:location][:address])})

Noting that you won't have an @location set (it will be nil because all 
instance variables are nil by default).
You need to actually get the params which will look something like: { location: 
{ address: entered value } }
You can probably see this in the development.log.
In Ruby, single-quoted strings do not do interpolation. Thus:
here = Cincinnati

puts 'coffee near #{here}'
coffee near #{here}

but:
puts coffee near #{here}
coffee near Cincinnati

so that should get you going again.

-Rob

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/C7D8086A-6B34-4002-8D67-A555010E2F33%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Help with small rails app

2014-10-21 Thread Rob Biedenharn
Oh, and:
 %= print #{@result['name']} %


can be simply:
%= @result['name'] %

The print output might end up in the log, but certainly won't be in the 
generated HTML.

And the result of what's inside %= ... % will be turned into a String (with 
.to_s if needed) and replace that bit of the template.

-Rob

On 2014-Oct-21, at 17:16 , Rob Biedenharn r...@agileconsultingllc.com wrote:

 
 On 2014-Oct-21, at 16:54 , Dominic Monaco jarvis...@gmail.com wrote:
 
 Hey guys I'm completely lost at this point I'm trying to make a simple app 
 that takes an input in the form of a string (City, State) and sends that 
 string to the google_places gem to do spot_by_query(gas station near 
 #{enter value from input})
 
 Then I need the 1st 10 results and be able to print out their names.  I have 
 become completely lost in my attempts and was looking for some advice. 
 
 Here is my controller
 class LocationsController  ApplicationController
   before_action :set_location, only: [:show, :edit, :update, :destroy]
 
   # GET /locations
   # GET /locations.json
   def index
 @location = Location.new
   end
 
   # GET /locations/1
   # GET /locations/1.json
   def show
 
   end
 
   # GET /locations/new
   def new
 
   end
 
   # POST /locations
   # POST /locations.json
   def create
 @client = GooglePlaces::Client.new('')
 
 @shops = @client.spots_by_query('coffee near 
 #{@location(params[:address])}')
 @result = JSON.parse(@shops[1])
 # @location.find_closest_shops(@location.params[:address])
   end
 
   private
 # Never trust parameters from the scary internet, only allow the white 
 list through.
 def location_params
   params.require(:location).permit(:address)
 end
 end
 
 
 Here is the input form
 %= form_for @location do |f| %
   %= f.label :address %
   %= f.text_field :address, :placeholder = City State %
   br
   %= f.submit Find Coffee! %
 % end %
 
 Here is the output form (this is where I'm lost)
 %= print #{@result['name']} %
 
 
 Well, after making a few assumptions:
 you are going to a URL that gets routed to the index action like /locations
 the form posts to /locations
 
 In your create action, you probably need to replace:
 @shops = @client.spots_by_query('coffee near 
 #{@location(params[:address])}')
 With:
 @shops = @client.spots_by_query(coffee near 
 #{location_params[:location][:address])})
 
 Noting that you won't have an @location set (it will be nil because all 
 instance variables are nil by default).
 You need to actually get the params which will look something like: { 
 location: { address: entered value } }
 You can probably see this in the development.log.
 In Ruby, single-quoted strings do not do interpolation. Thus:
 here = Cincinnati
 
 puts 'coffee near #{here}'
 coffee near #{here}
 
 but:
 puts coffee near #{here}
 coffee near Cincinnati
 
 so that should get you going again.
 
 -Rob
 
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/C7D8086A-6B34-4002-8D67-A555010E2F33%40agileconsultingllc.com.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/1541B0D1-F4CF-485C-BC43-474FB2FAD781%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Get the class name of the class who called the parent instance method.

2014-10-13 Thread Rob Biedenharn

On 2014-Oct-10, at 12:31 , Mike local@gmail.com wrote:

 You might want something like this.
 
 
 
 class Foo
 end
 
 Foo.instance_eval do
   def class_name
 self.name
   end
 end
 
 
 class Bar  Foo
 end
 
 class Tar  Foo
 end
 
 puts Foo.class_name
 #= Foo
 
 puts Bar.class_name
 #= Bar
 
 puts Tar.class_name
 #= Tar
 
 
 
 On Thursday, October 9, 2014 8:27:10 PM UTC-7, Alexandre Calvão wrote:
 Is not instance method, is class method... My bad
 
 
 ===
 Alexandre Mondaini Calvão
 
 Nossa recompensa se encontra no esforço e não no resultado. Um esforço total 
 é uma vitória completa. [Ghandi]
 
 2014-10-10 0:17 GMT-03:00 Alexandre Calvão apo...@gmail.com:
 Is there a way for me to do that on ruby ?
 
 class Foo
   def self.class_name
 self.class.name
   end
 end
 
 class Bar  Foo
 end
 
 class Tar  Foo
 end
 
 Bar.class_name 
 = 'Bar'
 
 Tar.class_name
 = 'Tar'
 
 I want to get the class name of the class who called the instance method from 
 the parent class.
 
 I tried the code above and it keeps getting me 'Class' as the result.
 
 Is that possible in ruby ?
 
 []`s
 
 ===
 Alexandre Mondaini Calvão
 
 Nossa recompensa se encontra no esforço e não no resultado. Um esforço total 
 é uma vitória completa. [Ghandi]
 


Why do anything fancy? An instance know which class it is. Just ask for the 
.class and then get that Class's .name.

irb2.1.3 class Foo; end
#2.1.3 = nil
irb2.1.3 class Bar  Foo; end
#2.1.3 = nil
irb2.1.3 class Baz  Foo; end
#2.1.3 = nil
irb2.1.3 foo = Foo.new
#2.1.3 = #Foo:0x007f98940cb528
irb2.1.3 foo.class.name
#2.1.3 = Foo
irb2.1.3 bar = Bar.new
#2.1.3 = #Bar:0x007f98940b55c0
irb2.1.3 bar.class.name
#2.1.3 = Bar
irb2.1.3 baz = Baz.new
#2.1.3 = #Baz:0x007f98940b38d8
irb2.1.3 baz.class.name
#2.1.3 = Baz

-Rob

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/F27EF066-FD80-4956-9E08-1203479AAA22%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Variable + string to specify variable

2014-07-31 Thread Rob Biedenharn

On 2014-Jul-30, at 10:59 , Eric Saupe ericsa...@gmail.com wrote:

 To expand on what Scott is saying here is some code that gives an example of 
 what he is referring to.
 
 id = 100
 x  = rand(1..3)
 arrays = [Array.new, Array.new, Array.new]
 selected_array = arrays[x]
 selected_array.push(id)

And to make it a bit more flexible, you could do:

arrays = [ Array.new,  Array.new,  Array.new ]
x = rand(arrays.size)
arrays[x].push(id)

or even:

arrays = [ Array.new,  Array.new,  Array.new ]
arrays.sample.push(id)

http://www.ruby-doc.org/core-2.1.2/Array.html#method-i-sample

-Rob

 
 On Tuesday, July 29, 2014 8:05:16 PM UTC-6, Scott Ribe wrote:
 On Jul 29, 2014, at 7:33 PM, Dave Castellano li...@ruby-forum.com wrote: 
 
  Novice question: 
  
  I need to assign an item id to one of 3 arrays randomly but can't figure 
  out how to specify the correct array by combining arr and the randomly 
  generated number... 
  
  id = 100 
  x = rand(1..3) 
  
  arr1 = Array.new 
  arr2 = Array.new 
  arr3 = Array.new 
  
  selected_array =  #{'arr' + x}  *** Not sure how to do this  
  
  selected_array.push(id) 
  
 
 While you could append the name and eval, that's not really a clean approach. 
 Just use an array of arrays. Or if else... 
 
 
 -- 
 Scott Ribe 
 scott...@elevated-dev.com 
 http://www.elevated-dev.com/ 
 (303) 722-0567 voice 
 
 
 
 
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/62d3b861-c606-4936-8540-08caae33e8fc%40googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/E2AC4C27-58EE-4FEF-8ABE-E85DC6DCA1DF%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Variable + string to specify variable

2014-07-31 Thread Rob Biedenharn
You can simplify the arrays construction, too: (with slight reformatting of the 
arrays output)

irb2.1.1 arrays = Array.new(3) { Array.new }
#2.1.1 = [[], [], []]
irb2.1.1 100.times {|id| arrays.sample.push(id) }
#2.1.1 = 100
irb2.1.1 arrays
#2.1.1 = [[0, 2, 6, 8, 9, 11, 14, 16, 17, 18, 22, 
24, 29, 31, 37, 42, 47, 49, 53, 54, 57, 
58, 60, 68, 69, 73, 75, 79, 80, 81, 83, 
88, 91, 94, 95, 96], 
   [1, 3, 12, 13, 20, 25, 26, 28, 33, 34,
38, 39, 43, 44, 48, 50, 52, 59, 63, 65,
70, 72, 74, 77, 78, 82, 86, 87, 89, 97],
   [4, 5, 7, 10, 15, 19, 21, 23, 27, 30, 
32, 35, 36, 40, 41, 45, 46, 51, 55, 56,
61, 62, 64, 66, 67, 71, 76, 84, 85, 90,
92, 93, 98, 99]]
irb2.1.1 arrays.map(:size)
#2.1.1 = [36, 30, 34]

On 2014-Jul-31, at 12:00 , Eric Saupe ericsa...@gmail.com wrote:

 I knew there would be a nice simpler Ruby way. I love the second solution, 
 Rob. Below is the updated example.
 id = 100
 arrays = [Array.new, Array.new, Array.new]
 arrays.sample.push(id)
 
 On Thursday, July 31, 2014 8:45:33 AM UTC-6, Rob Biedenharn wrote:
 
 On 2014-Jul-30, at 10:59 , Eric Saupe eric...@gmail.com wrote:
 
 To expand on what Scott is saying here is some code that gives an example of 
 what he is referring to.
 
 id = 100
 x  = rand(1..3)
 arrays = [Array.new, Array.new, Array.new]
 selected_array = arrays[x]
 selected_array.push(id)
 
 And to make it a bit more flexible, you could do:
 
 arrays = [ Array.new,  Array.new,  Array.new ]
 x = rand(arrays.size)
 arrays[x].push(id)
 
 or even:
 
 arrays = [ Array.new,  Array.new,  Array.new ]
 arrays.sample.push(id)
 
 http://www.ruby-doc.org/core-2.1.2/Array.html#method-i-sample
 
 -Rob
 
 
 On Tuesday, July 29, 2014 8:05:16 PM UTC-6, Scott Ribe wrote:
 On Jul 29, 2014, at 7:33 PM, Dave Castellano li...@ruby-forum.com wrote: 
 
  Novice question: 
  
  I need to assign an item id to one of 3 arrays randomly but can't figure 
  out how to specify the correct array by combining arr and the randomly 
  generated number... 
  
  id = 100 
  x = rand(1..3) 
  
  arr1 = Array.new 
  arr2 = Array.new 
  arr3 = Array.new 
  
  selected_array =  #{'arr' + x}  *** Not sure how to do this  
  
  selected_array.push(id) 
  
 
 While you could append the name and eval, that's not really a clean 
 approach. Just use an array of arrays. Or if else... 
 
 
 -- 
 Scott Ribe 
 scott...@elevated-dev.com 
 http://www.elevated-dev.com/ 
 (303) 722-0567 voice 
 
 
 
 
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-ta...@googlegroups.com.
 To post to this group, send email to rubyonra...@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/62d3b861-c606-4936-8540-08caae33e8fc%40googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.
 
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/931a7b70-e8bf-464a-90d8-ae0f4682ee3a%40googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/DB2AC111-429D-47A8-9497-9F988036BA24%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Updating Rails 2 to Rails 3 or 4

2014-07-03 Thread Rob Biedenharn

On 2014-Jul-3, at 11:25 , Jason Fleetwood-Boldt t...@datatravels.com wrote:
 As was suggested to you by other posters, please read the upgrade guide 
 carefully (here is the official one 
 http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html) 
 
 it is recommended that you have very good test coverage before you begin. 
 
 I suggest you use a tool like simple-cov to make sure all your lines of code 
 are tested before you begin, as well I'd recommend integration coverage for 
 every major end-user happy path through your app. 
 
 When you are sure you have complete test coverage, change the version in the 
 Gemfile and then run bundle update rails
 
 
 On Jul 3, 2014, at 10:28 AM, M,Gopi M.gopinath gopi170...@gmail.com wrote:
 
 Hi,
   Seems I need to say this first, The website which I 
 have Know is 8 Years old website, Developed in Ruby 1.8.6 and Rails 2.3.6, 
 and its as 220 tables in it and lot of controllers and views. Is there a way 
 to update this to current version of rails and ruby. 

The short answer is yes, but it is certainly not easy, nor can you make a 
single leap.

Simple-cov will not help you yet as it requires ruby 1.9.3 or better. (It's 
been so long that I can't even remember if there was a similar tool that worked 
with ruby 1.8.6.)

You may find it simpler to write a new app from scratch, importing (by the 
time-honored cut-and-paste method) the important bits of business logic.

However, if you want to proceed with an upgrade, this is roughly what you'd 
need to do:

* update to rails-2.3.18
There's really no reason not to and PLENTY of good reasons that you 
should have done this already.
2.3.9 (2010-09-04) was the version that first gave deprecation warnings 
for the upgrade to rails-3.0
2.3.18 (2013-03-18) was the last releast in the 2.3 line and contains 
fixes for at least 10 vulnerabilities (some of them quite serious!)

* get all your tests to pass (if you don't *have* tests, you'd better have 
faith)
* address all the deprecation warnings

* don't upgrade ruby yet

https://developer.uservoice.com/blog/2012/03/04/how-to-upgrade-a-rails-2-3-app-to-ruby-1-9-3/
But you might have to upgrade to ruby-1.8.7 as rails-3.0 doesn't 
officially support 1.8.6)

* upgrade to rails-3.0.0 (perhaps even directly to rails-3.0.20)
* get all your tests to pass

* upgrade to ruby-1.9.2 (or perhaps even ruby-1.9.3)
* get all your tests to pass

* upgrade to rails-3.1.12 (last of the rails-3.1 line)
This might not strictly be required, but 3.1 introduced the Asset 
Pipeline and also made jQuery the default JavaScript framework.
If you have much use of Prototype or Scriptaculous in your application, 
it would probably be a good idea to convert that to jQuery (and get 
https://github.com/rails/jquery-ujs)
* get all your tests to pass

* upgrade to rails-3.2.19
* get all your tests to pass

* upgrade to ruby-2.1.2 (there's probably no reason to just use 2.0 at this 
point)
* get all your tests to pass

* upgrade to rails-4.0.8
* get all your tests to pass

* upgrade to rails-4.1.4
* cope with the new secrets.yml file
* get all your tests to pass

* take a vacation

Seriously, there's a lot to do if you really want to go the upgrade route. I 
haven't even mentioned any of the issues that you're almost certain to 
encounter with gems that cease to function with newer versions of Rails or even 
newer Rubies. I'd recommend that you very seriously consider refreshing the 
application as a simpler way to bring the application onto a current, supported 
RoR stack.

-Rob

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/F60098D9-F540-4976-A917-DBD8E47D7F3E%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Updating Rails 2 to Rails 3 or 4

2014-07-03 Thread Rob Biedenharn

On 2014-Jul-3, at 15:49 , Rob Biedenharn r...@agileconsultingllc.com wrote:

 
 On 2014-Jul-3, at 11:25 , Jason Fleetwood-Boldt t...@datatravels.com wrote:
 As was suggested to you by other posters, please read the upgrade guide 
 carefully (here is the official one 
 http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html) 
 
 it is recommended that you have very good test coverage before you begin. 
 
 I suggest you use a tool like simple-cov to make sure all your lines of code 
 are tested before you begin, as well I'd recommend integration coverage for 
 every major end-user happy path through your app. 
 
 When you are sure you have complete test coverage, change the version in the 
 Gemfile and then run bundle update rails
 
 
 On Jul 3, 2014, at 10:28 AM, M,Gopi M.gopinath gopi170...@gmail.com wrote:
 
 Hi,
   Seems I need to say this first, The website which I 
 have Know is 8 Years old website, Developed in Ruby 1.8.6 and Rails 2.3.6, 
 and its as 220 tables in it and lot of controllers and views. Is there a 
 way to update this to current version of rails and ruby. 
 
 The short answer is yes, but it is certainly not easy, nor can you make a 
 single leap.
 
 Simple-cov will not help you yet as it requires ruby 1.9.3 or better. (It's 
 been so long that I can't even remember if there was a similar tool that 
 worked with ruby 1.8.6.)
 
 You may find it simpler to write a new app from scratch, importing (by the 
 time-honored cut-and-paste method) the important bits of business logic.
 
 However, if you want to proceed with an upgrade, this is roughly what you'd 
 need to do:
 
 * update to rails-2.3.18
   There's really no reason not to and PLENTY of good reasons that you 
 should have done this already.
   2.3.9 (2010-09-04) was the version that first gave deprecation warnings 
 for the upgrade to rails-3.0
   2.3.18 (2013-03-18) was the last releast in the 2.3 line and contains 
 fixes for at least 10 vulnerabilities (some of them quite serious!)
 
 * get all your tests to pass (if you don't *have* tests, you'd better have 
 faith)
 * address all the deprecation warnings
 
 * don't upgrade ruby yet
   
 https://developer.uservoice.com/blog/2012/03/04/how-to-upgrade-a-rails-2-3-app-to-ruby-1-9-3/
   But you might have to upgrade to ruby-1.8.7 as rails-3.0 doesn't 
 officially support 1.8.6)

Oh, and I took a look at 
http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html as suggested by 
Jason Fleetwood-Boldt and that has a MUCH more detailed walk though the upgrade 
process from 3.0 to 4.1. But if you don't have time to go and look at that 
yourself, then perhaps I've given you enough with which to weigh the upgrade v. 
rewrite paths.

-Rob

 * upgrade to rails-3.0.0 (perhaps even directly to rails-3.0.20)
 * get all your tests to pass
 
 * upgrade to ruby-1.9.2 (or perhaps even ruby-1.9.3)
 * get all your tests to pass
 
 * upgrade to rails-3.1.12 (last of the rails-3.1 line)
   This might not strictly be required, but 3.1 introduced the Asset 
 Pipeline and also made jQuery the default JavaScript framework.
   If you have much use of Prototype or Scriptaculous in your application, 
 it would probably be a good idea to convert that to jQuery (and get 
 https://github.com/rails/jquery-ujs)
 * get all your tests to pass
 
 * upgrade to rails-3.2.19
 * get all your tests to pass
 
 * upgrade to ruby-2.1.2 (there's probably no reason to just use 2.0 at this 
 point)
 * get all your tests to pass
 
 * upgrade to rails-4.0.8
 * get all your tests to pass
 
 * upgrade to rails-4.1.4
 * cope with the new secrets.yml file
 * get all your tests to pass
 
 * take a vacation
 
 Seriously, there's a lot to do if you really want to go the upgrade route. I 
 haven't even mentioned any of the issues that you're almost certain to 
 encounter with gems that cease to function with newer versions of Rails or 
 even newer Rubies. I'd recommend that you very seriously consider 
 refreshing the application as a simpler way to bring the application onto a 
 current, supported RoR stack.
 
 -Rob
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/F60098D9-F540-4976-A917-DBD8E47D7F3E%40agileconsultingllc.com.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion

Re: [Rails] rake aborated

2014-06-02 Thread Rob Biedenharn

On 2014-Jun-2, at 09:30 , Walter Lee Davis wa...@wdstudio.com wrote:

 This is normal. You need to run Rake from within the same folder as a 
 Rakefile, as the error indicates.
 
 Make sure that your PATH is set to include the folder where rake lives, so 
 that you can type the command from anywhere (not a fully-qualified path to 
 the executable as you seem to have done here) and it will pick up the current 
 folder as its working environment.
 
 Walter

Actually, rake will search upwards in the directory structure to find a 
Rakefile (with any of the names indicated) and then the tasks will be executed 
with the current directory set to where the Rakefile was found.

This allows you to be in a subdirectory of a project and still issue the rake 
commands. Of course, now that Rails expects you to have ./bin in your PATH, 
finding the rake executable is a bit more complicated than it used to be.

-Rob

 
 On Jun 2, 2014, at 9:24 AM, Rachita Dangare wrote:
 
 Hi
 
 I have installed gem install rake on my machine.
 but when I run command rake
 
 C:\Ruby193\lib\ruby\gems\1.9.1rake
 
 it gives error message as
 
 rake aborted!
 No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb,
 Rakefile.rb)
 
 (See full trace by running task with --trace)
 
 kindly help me.
 
 Thanks,
 Rachita
 
 -- 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/754D4C11-3443-458F-95AA-B8DA9D7B68DC%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Use table elements

2014-05-22 Thread Rob Biedenharn

On 2014-May-22, at 15:39 , Colin Law clan...@gmail.com wrote:

 On 22 May 2014 18:17, Fab Forestier li...@ruby-forum.com wrote:
 Colin Law wrote in post #1146811:
 On 22 May 2014 16:00, Fab Forestier li...@ruby-forum.com wrote:
 
 You said that, for example, the link should take you to the edit page
 of an article.  How does the user know what article that is?
 
 Colin
 
 No by exemple I understand the action of the button but it's a totally
 different think my button has to redirect to an Operation view but it is
 not an edit view it's a view created by me, and this operation has to be
 the operation in the same line in the table with the button.
 
 You don't redirect to a view using a link or button, you request an
 action in a controller, it is important to use the right words or we
 will all be confused.  It must be particularly difficult when one is
 not working in one's native language, I understand that.
 
 So, when the button is clicked you need to request an action in a
 controller, and from that you can then show whatever view you like.
 So do you know what action you wish to invoke?
 
 Colin

Fab,
You seem to have put several concepts into one description of the problem.

Perhaps if you break it into its parts like:

* The link/button initiates a request back to the server
  ( link_to(Text, my_view_path(article), remote: true) )

* The config/routes.rb specifies how a request is directed to a particular 
controller/action

* The action can use the params from the request to determine what to render or 
where to redirect.

Does that help you either understand the problem or at least indicate which 
part you really have a question about?

-Rob

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/0F374511-AA05-4577-B74B-6A17F93A975C%40agileconsultingllc.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Activity streams/News feeds with Aggregation, MySQL and Redis support

2014-03-21 Thread Rob Biedenharn
http://www.ruby-doc.org/stdlib-2.1.1/libdoc/rss/rdoc/RSS.html

Rob Biedenharn
rob.biedenh...@gmail.com



On 2014-Mar-21, at 13:39 , Kenny Meyer knny.m...@gmail.com wrote:

 Can anyone recommend a gem/library?
 
 On Friday, March 21, 2014 2:38:45 PM UTC-3, Kenny Meyer wrote:
 I need to implement an activity feed for a Rails application with the 
 following features:
 
  - Needs to work with MySQL database
  - Needs to support aggregations for similar feed stories (like Facebook)
  
 There is a library out there for Python, Feedly 
 https://github.com/tschellenbach/Feedly, which seems to be an EXACT match for 
 what I am trying to build, but well.. I need it in Ruby.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/4fa4894b-3d9a-430e-8ad7-9f689362e8d9%40googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/A6D45CF8-A98D-4E67-8AED-5CA60E1B1E9F%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] How to start new pages automatically whenever the text string cannot fit on the current page in praw

2014-01-16 Thread Rob Biedenharn
On 2014-Jan-16, at 04:45 , DHEERAJ CHILAPPAGARI dheeru.manth...@gmail.com 
wrote:

 I am trying to generate a PDF invoice using prawn with header, body and 
 footer. The content of the body may change. I'm using bounding_box to place 
 content in the body. If the content cannot fit on the current page body, it 
 should automatically place the remaining content in body portion of the new 
 page. Please help me with the coding.

This is the default behavior of Prawn. You should find an example of exactly 
this in the manual.
http://prawn.majesticseacreature.com/manual.pdf

-Rob

Rob Biedenharn
rob.biedenh...@gmail.com


-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/A8ABB2B1-4253-489E-A55C-093913B4D8E6%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [Rails] Rails Engines problem: routing_error.erb within rescues/layout

2013-12-26 Thread Rob Biedenharn
On 2013-Dec-26, at 15:41 , jsnark s...@monmouth.com wrote:

 I'm working through the Rails Engines tutorial at 
 http://edgeguides.rubyonrails.org/engines.html.  I'm using ruby 1.9.3 and 
 rails 3.1.12 on Linux.  I'm stuck on section 4.1.  When I try to access 
 localhost:3000/blog I get:
 
 Started GET /blog for 127.0.0.1 at 2013-12-26 15:25:12 -0500
 
 ActionController::RoutingError (No route matches [GET] /blog):  
 
 Rendered 
 /home/XXX/.rvm/gems/ruby-1.9.3-p484/gems/actionpack-3.1.12/lib/action_dispatch/middleware/templates/rescues/routing_error.erb
  within rescues/layout (47.4ms)
 
 But, It looks like that should be a valid route:
 
 $ rake routes
 blorgh  /blog {:to=Blorgh::Engine}

If you haven't already, try restarting your local Rails application. I've lost 
track of what still doesn't get reloaded automatically, but stoping the local 
app and restarting tends to cure quite a lot of these issues.

In particular, if you added the route *after* the application was started, 
there's a good chance that the running application doesn't actually know even 
though the `rake routes` command claims it exists (since it just freshly loaded 
everthing ;-).

-Rob

 
 The engine is included in the bundle:
 
 $ bundle show
 Gems included by the bundle:
   * actionmailer (3.1.12)
   * actionpack (3.1.12)
   * activemodel (3.1.12)
   * activerecord (3.1.12)
   * activeresource (3.1.12)
   * activesupport (3.1.12)
   * ansi (1.4.3)
   * arel (2.2.3)
   * blorgh (0.0.1)
   * builder (3.0.4)
   * bundler (1.3.5)
   * coffee-rails (3.1.1)
   * coffee-script (2.2.0)
   * coffee-script-source (1.6.3)
   * erubis (2.7.0)
   * execjs (2.0.2)
   * hike (1.2.3)
   * i18n (0.6.9)
   * jquery-rails (3.0.4)
   * json (1.8.1)
   * libv8 (3.16.14.3)
   * mail (2.4.4)
   * mime-types (1.25.1)
   * multi_json (1.8.2)
   * polyglot (0.3.3)
   * rack (1.3.10)
   * rack-cache (1.2)
   * rack-mount (0.8.3)
   * rack-ssl (1.3.3)
   * rack-test (0.6.2)
   * rails (3.1.12)
   * railties (3.1.12)
   * rake (10.1.1)
   * rdoc (3.12.2)
   * ref (1.0.5)
   * sass (3.2.13)
   * sass-rails (3.1.7)
   * sprockets (2.0.4)
   * sqlite3 (1.3.8)
   * therubyracer (0.12.0)
   * thor (0.14.6)
   * tilt (1.3.7)
   * treetop (1.4.15)
   * turn (0.8.3)
   * tzinfo (0.3.38)
   * uglifier (2.4.0)
 
 Where should I look for the error?
 
 Thanks.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/931bc974-e185-4a7f-96fe-b2c5a93d8db2%40googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/5EB365A6-32C2-415F-B8C5-3C59273F52DF%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [Rails] Search

2013-12-23 Thread Rob Biedenharn
On 2013-Dec-24, at 01:45 , Daynthan Kabilan dayantha...@gmail.com wrote:

 Hi all,
 
 how to avoid single quote in our rails search
 
 Example
 
 in my users table  user_name=ram'kumar
 
 my search query
 
 params[:name]=ramkumar
 
 @ans=Users.where(user_name=?,params[:name])

@ans = User.where(user_name: params[:name])

and let the ActiveRecord gem sanitize the parameters

If you're not using the latest version of Rails, you'll need to give more 
specifics before you can get better help.

-Rob

 
 how can i get the value?
 
 any one give me a solution
 
 
 Thankyou.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/CADKeJyRuuoBPCvs3-5MP8PJQLrLBWrdCVhPoj4K9UeSC9fxj5Q%40mail.gmail.com.
 For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/B9D88497-1983-4550-9CDC-360F6DACFAC3%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [Rails] Rails 4, subdomain routing

2013-11-21 Thread Rob Biedenharn
On 2013-Nov-21, at 04:12 , Tamara Temple tamouse.li...@gmail.com wrote:

 
 On Nov 20, 2013, at 4:04 AM, Srdjan Cengic cengas...@gmail.com wrote:
 
 Far as i know, link to http://api.localhost:3000/posts should work but i get 
 routing error: 
 No route matches [GET] /posts (Same with /posts.json)
 
 This isn’t how localhost works, at all.
 
 If you need to set up a local subdomain for testing, you most likely will 
 need to do things like modify your /etc/hosts table, set up local DNS 
 resolvers, and the like. If you’re running on a mac, you can use pow, which 
 makes all that dead-easy.

But you could use:
http://api.127.0.0.1.xip.io:3000/posts

See http://xip.io/ for the details, but this will resolve to the IP address 
before the .xip.io and then api will be the subdomain.

-Rob

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/9BD1A639-67DB-4C89-B098-E725D897B52C%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [Rails] :layout = question

2013-09-11 Thread Rob Biedenharn
On 2013-Sep-11, at 19:06 , Dave Aronson wrote:

 On Wed, Sep 11, 2013 at 7:00 PM, jmcguckin mcguc...@gmail.com wrote:
 
 In a controller action for 'show' is the following:
 
render :layout = 'edit'
 
 Ok, there a layout for edit, basically it is the standard javascript
 includes, anti csfr stuff and 'yield'.
 
 Hmm, what's it yielding to? Which template is it yielding to? There are both
 'edit.html.erb' and  'show.html.erb' templates.
 
 It would be yielding to whatever template the controller action would
 be using.  In this case, that would be show.html.erb, since you're in
 the show action.
 
 -Dave
 
 -- 
 Dave Aronson, the T. Rex of Codosaurus LLC,
 secret-cleared freelance software developer
 taking contracts in or near NoVa or remote.
 See information at http://www.Codosaur.us/.


The part that is (probably) causing you to think something's odd is that the 
view is actually processed first. The result and any 'content_for' sections 
have been saved before the layout is processed. The main result of the view is 
inserted where the `yield` is processed and the result of a `content_for :foo` 
will be inserted if there is a `yield :foo`.

-Rob

Rob Biedenharn
rob.biedenh...@gmail.com


-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/4671F36A-5641-4CD3-B375-7251A87FCCA0%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [Rails] fetch the Hash from a string

2013-08-26 Thread Rob Biedenharn

On 2013-Aug-26, at 17:10 , Love U Ruby wrote:

 tamouse m. wrote in post #1119628:
 On Aug 26, 2013, at 2:42 PM, Love U Ruby li...@ruby-forum.com wrote:
 
 
 You have a string which represents a what a Hash looks like. Why not run
 it through eval and see what you get?
 
 my_hash = eval(new_str)
 
 I was trying to avoid `eval`. I tried also the `yaml`. But no luck :(


If all your keys and values are just digits (i.e., String#to_i likes them), 
then you can easily avoid eval and yaml. Just make your own parser.  Here are 
some learning tests to get you started. If you avoid scrolling down too far 
to see my answer, then just make the tests pass and you're done!

Of course, you can also expand the tests to cover even more exotic hash keys 
and values, but if you go too far you've just reinvented YAML or JSON with 
different syntax.

-Rob


require 'minitest/autorun'

class TestSomeCrappyMarkupLanguage  Minitest::Test
  def setup
@str = 1=2,3=(4=5,6=7)
  end

  def test_nil
refute SomeCrappyMarkupLanguage.parse(nil)
  end

  def test_empty_string
assert_equal({}, SomeCrappyMarkupLanguage.parse())
  end

  def test_simple_hash
assert_equal({1=2}, SomeCrappyMarkupLanguage.parse(1=2))
  end

  def test_two_elements
assert_equal({4=5,6=7}, SomeCrappyMarkupLanguage.parse(4=5,6=7))
  end

  def test_nested
expected = { 1 = 2, 3 = { 4 = 5, 6 = 7 } }
assert_equal expected, SomeCrappyMarkupLanguage.parse(@str)
  end

end

# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...
# spoilers below...

class SomeCrappyMarkupLanguage
  def self.parse(str)
return nil unless str
result = {}
str.scan(/(\d+)=((?:\([^\)]*\))|\d+),?/).each do |key,value|
  key = key.to_i
  value = value =~ /\A\d+\z/ ? value.to_i : parse(value)
  result[key] = value
end
result
  end
end


-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/B705512C-FD76-4F45-BE2D-81DD0904DCA0%40agileconsultingllc.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [Rails] Re: Re: Validations not working on complex DB transaction

2013-08-06 Thread Rob Biedenharn

On 2013-Aug-6, at 10:13 , masta Blasta wrote:

 selva4...@gmail.com wrote in post #1117870:
 Hi,
 
 The @user object is getting saved first. That time, there is no
 instuition membership attached to it. So one is getting created. Then
 when you save the instuition membership again inside the controller it
 also gets saved.
 
 Is this clear?
 
 You just restated what i had initially written.
 
 
 The problem is something to do with how rails connects newly 
 initialized objects that are in memory but not yet in the database.
 
 We have built two objects like this
 u = User.new
 im = InstitutionMembership.new :user = u
 
 At that point the u (User) object doesn't know anything about the im 
 object. Saving the u object does not trigger an autosave on the 
 association, and the create callback creates a new membership. That's 
 somewhat expected.

So tell ActiveRecord that you *want* the autosave:

class User  ActiveRecord::Base
belongs_to :account
has_many :institution_memberships, :autosave = :always
has_many :institutions, :through = :institution_memberships

after_create :set_default_membership

def set_default_membership 
  if institution_memberships(true).blank? 
institution_memberships.create(default_data_from_account) 
  end 
end 
end 

class InstitutionMembership  ActiveRecord::Base
belongs_to :user
belongs_to :institution
validates_uniqueness_of :user_id, :scope = :institution_id 
end

Note the argument to 'institution_memberships(true)' which causes the 
memberships to be reloaded from the database.

 
 The odd issues appear after -
 u = User.new
 im = InstitutionMembership.new :user = u
 u.save
 im.save

I assume that you've simplified this so that the account_id or however the 
default_data_from_account manages to find the institution_id is missing.

u = User.new
u.institutions  Institution.find(somehow)

or

u = User.new
u.institution_memberships  InstitutionMembership.new(:institution_id = 
from_a_parameter_perhaps)

and then the u.save should do the right thing.

-Rob

 
 'im' is aware of the user object, however it is not able to validate 
 against it. When it attempts to validate, the user_id==NULL. At the very 
 next log entry though, it saves itself with the correct user_id. So 
 somewhere between the validate callbacks, and the create and commit 
 callbacks, the 'im' object refreshed the user object and retrieved the 
 user_id. Also the new_record? flag on 'im' is still set, so a new row is 
 created.
 
 One of the better solutions was actually to do:
 u = User.new
 im = u.institution_memberships.build
 
 This is able to properly connect the objects in memory, and the process 
 works smoothly. The association is autosaved on u.save
 
 -- 
 Posted via http://www.ruby-forum.com/.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/fc9852aaa5e23f13c8185ac013988a08%40ruby-forum.com.
 For more options, visit https://groups.google.com/groups/opt_out.
 
 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/96105FD7-E973-459F-AF68-27EF426A35C4%40agileconsultingllc.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Re: Re: [Rails] Validations not working on complex DB transaction

2013-08-06 Thread Rob Biedenharn

On 2013-Aug-6, at 10:13 , masta Blasta wrote:

 selva4...@gmail.com wrote in post #1117870:
 Hi,
 
 The @user object is getting saved first. That time, there is no
 instuition membership attached to it. So one is getting created. Then
 when you save the instuition membership again inside the controller it
 also gets saved.
 
 Is this clear?
 
 You just restated what i had initially written.
 
 
 The problem is something to do with how rails connects newly 
 initialized objects that are in memory but not yet in the database.
 
 We have built two objects like this
 u = User.new
 im = InstitutionMembership.new :user = u
 
 At that point the u (User) object doesn't know anything about the im 
 object. Saving the u object does not trigger an autosave on the 
 association, and the create callback creates a new membership. That's 
 somewhat expected.

So tell ActiveRecord that you *want* the autosave:

class User  ActiveRecord::Base
belongs_to :account
has_many :institution_memberships, :autosave = :always
has_many :institutions, :through = :institution_memberships

after_create :set_default_membership

def set_default_membership 
 if institution_memberships(true).blank? 
   institution_memberships.create(default_data_from_account) 
 end 
end 
end 

class InstitutionMembership  ActiveRecord::Base
belongs_to :user
belongs_to :institution
validates_uniqueness_of :user_id, :scope = :institution_id 
end

Note the argument to 'institution_memberships(true)' which causes the 
memberships to be reloaded from the database and the :autosave option added to 
the has_many.

 
 The odd issues appear after -
 u = User.new
 im = InstitutionMembership.new :user = u
 u.save
 im.save

I assume that you've simplified this so that the account_id or however the 
default_data_from_account manages to find the institution_id is missing.

u = User.new
u.institutions  Institution.find(somehow)

or

u = User.new
u.institution_memberships  InstitutionMembership.new(:institution_id = 
from_a_parameter_perhaps)

and then the u.save should do the right thing.

-Rob

 
 'im' is aware of the user object, however it is not able to validate 
 against it. When it attempts to validate, the user_id==NULL. At the very 
 next log entry though, it saves itself with the correct user_id. So 
 somewhere between the validate callbacks, and the create and commit 
 callbacks, the 'im' object refreshed the user object and retrieved the 
 user_id. Also the new_record? flag on 'im' is still set, so a new row is 
 created.
 
 One of the better solutions was actually to do:
 u = User.new
 im = u.institution_memberships.build
 
 This is able to properly connect the objects in memory, and the process 
 works smoothly. The association is autosaved on u.save
 
 -- 
 Posted via http://www.ruby-forum.com/.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/fc9852aaa5e23f13c8185ac013988a08%40ruby-forum.com.
 For more options, visit https://groups.google.com/groups/opt_out.
 
 


-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/27496B38-FDB8-4F74-A6BB-73888B537DA3%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] help regarding internationalization for bootstrap button.

2013-07-18 Thread Rob Biedenharn

On 2013-Jul-18, at 04:51 , Tushar Patil wrote:

 Hi, 
 Here i mention my hi.bootstrap.yml file, and i use 
 create company = key use in form.html
 
 %= f.submit t('.create company', :default = t(helpers.links.Create 
 Company)), :class = 'btn btn-primary' %
 
 It works fine for Hindi, but it gives problem for English
 
 hi:
  helpers:
   actions:  क्रिया
 
  links:
Edit:संपादित करें
new: नई
update:  अपडेट
cancel:  रद्द करें
enable:  द्रश्य
disable: अदृश्य
Create Company:  कंपनी बनाएं
Delete:  हटाना
 
 Let me know where i am wrong

Have you tried putting quotes around the key having a space?

  Create Company:  कंपनी बनाएं

Having extra space between the : and the value does not matter (especially 
since you have a quoted value). The only difference that an unquoted value 
would have is all the leading spaces would be removed from the value.

-Rob


 
 On Wednesday, July 17, 2013 8:31:08 PM UTC+5:30, tamouse wrote:
 Pardon the follow up on myself… 
 
 On Jul 17, 2013, at 7:55 AM, Tamara Temple tamous...@gmail.com wrote: 
 
  
  On Jul 17, 2013, at 4:39 AM, Colin Law cla...@googlemail.com wrote: 
  
  On 17 July 2013 12:24, Tushar Patil tushar...@gmail.com wrote: 
  Hi, 
  I am trying  to convert my application in hindi, I am stuck in the 
  renaming 
  submit button name, It works fine for hindi but not working for english, 
  it 
  gives syntax error, here is my submit button code 
  
  %= f.submit  t('.Create Company', :default = t(helpers.links.Create 
  Company)), :class = 'btn btn-primary' % 
  
  I have not used internationalisation, but should that be 
  %= f.submit  t('.Create Company'), :default = t(helpers.links.Create 
  Company), :class = 'btn btn-primary' % 
  
  
  In this case, probably not -- the #t helper takes a default: option in case 
  the first item is not found in the translation tables. 
  
  I suspect the key '.Create Company' to be the culprit -- and actually I 
  think the leading '.' in this case might be the problem. Very hard to tell 
  without seeing the translation tables. Making a translation key a spaced 
  phrase with capitals is unusual as well -- these things are keys, and just 
  seeing this seems odd to me. It might work? It certainly seems to be 
  working for the default translation token. 
  
  Tushar, please paste in the segments from each of your translation files so 
  we can see the actual code? 
  
  Colin 
  
  
  Create Company = mention in the hi.bootstrap.yml file 
  Please, let me know where i am wrong. 
 
 
 Tushar, please try this: remove the default: from the t() call, and see if 
 you get the translation not found error? 
 
 % f.submit t('.Create Company'), class: 'btn btn-primary' % 
 
 
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/45456acb-e2da-4981-ac67-78e71686736a%40googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.
  
  

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/B8A380BA-12C5-4BC6-93CD-2237EDA55E14%40agileconsultingllc.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] Delayed job in Rails 4

2013-07-08 Thread Rob Biedenharn

On 2013-Jul-8, at 12:15 , Karthikeyan A K wrote:

 I gem file I added this:
 
 gem 'delayed_job_active_record'
 
 Then when I bundled, this happened:
 
 $ bundle
 Fetching gem metadata from https://rubygems.org/..
 Fetching gem metadata from https://rubygems.org/..
 Resolving dependencies...
 Bundler could not find compatible versions for gem activesupport:
  In Gemfile:
delayed_job_active_record (= 0) ruby depends on
  activesupport (~ 3.0) ruby

You are aware that ~3.0 is like =3.0 AND 4

 
sass-rails (~ 4.0.0) ruby depends on
  activesupport (4.0.0)

Similarly, ~4.0.0 means =4.0.0 AND 4.1

Your delayed_job_active_record gem doesn't yet say that it works with 4.x. It 
might, but the author was (correctly!) conservative and needs to update the 
gem's dependencies.

-Rob

 
 -- 
 Posted via http://www.ruby-forum.com/.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/04f82b0c5273262e568ed164b99313fc%40ruby-forum.com.
 For more options, visit https://groups.google.com/groups/opt_out.
 
 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/950E72B1-E6AA-4EA2-940A-791CE61A7544%40agileconsultingllc.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] Skip index in array.each_with_index loop

2013-05-23 Thread Rob Biedenharn

On 2013-May-23, at 05:24 , Ajit Teli wrote:

 Can anyone help me on how to skip index in ARRAY.each_with_index loop?
 
 Please look at below case:
 
 In a ARRAY.each_with_index loop, I would like increase the index by 10
 whenever a condition is met.
 
 arr is array of numbers from 0 to 50
 arr.each_with_index do |x,i|
  if i % 10 == 0
puts #{x} at #{i}
i = i+10  //index increased by 10
  end
 end
 
 The output should be:
 10 at 10
 30 at 30
 50 at 50
 
 Thanks
 Ajit

You need to think about what you really need to do, look at the options to use 
select or reject/delete_if, or take the time to understand what next does. Of 
course, you don't seem to have even tried to run your code since your output 
lacks 0 at 0.

-Rob

For example:

irb2.0.0 arr = (0..50).to_a
#2.0.0 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]
irb2.0.0   arr.each_with_index do |element,index|
?  next unless index % 10 == 0
irb2.0.0 puts #{element} at #{index}
irb2.0.0   end
0 at 0
10 at 10
20 at 20
30 at 30
40 at 40
50 at 50
#2.0.0 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]
irb2.0.0   arr.each.with_index.select {|element,index| index % 10 == 0}.each 
do |element,index|
?  puts #{element} at #{index}
irb2.0.0   end
0 at 0
10 at 10
20 at 20
30 at 30
40 at 40
50 at 50
#2.0.0 = [[0, 0], [10, 10], [20, 20], [30, 30], [40, 40], [50, 50]]


-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/4FA0239B-28B5-4432-B4DC-E578C5C50BB5%40agileconsultingllc.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] ERROR: Could not find a valid gem 'rails' (= 0), here is why: Unable to download data from

2013-04-12 Thread Rob Biedenharn
On 2013-Apr-12, at 14:02 , Phawin Khongkhasawan wrote:

 I want to install Rails on my Raspberry Pi
 
 but i got message
 
 ERROR: Could not find a valid gem 'rails' (= 0), here is why: Unable to 
 download data fromhttp://rubygems.org/ - no such name 
 (http://rubygems.org/latest_specs.4.8.gz)
 
 How can I solve this problem?
 

Well, this is probably more than you need, but it does include everything that 
you need to get a Rails development system on the Pi.

http://rabiedenharn.tumblr.com/post/35572989949/making-a-custom-raspberry-pi-image

-Rob

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] using multiple joins in queries

2013-03-21 Thread Rob Biedenharn

On Mar 20, 2013, at 6:04 PM, John Merlino wrote:

 I have this query:
 
 Report.
joins(:alerts).
joins(:alert_code).

I think that you're looking for 'includes' rather than 'joins' for these 
associations.

Report.includes({:alerts = :alert_code}).

To use joins, you would have to supply more SQL-ish clauses, not symbols for 
the associations.

http://apidock.com/rails/v3.2.8/ActiveRecord/QueryMethods/joins
http://apidock.com/rails/v3.2.8/ActiveRecord/QueryMethods/includes

-Rob

where(:unit_id = unit_id).
where{time  my{self.time}}.
where(alert_codes.name LIKE ?, %Inside virtual
 fence%).
order(reports.time DESC).first
 
 Basically, it breaks:
 
 ActiveRecord::ConfigurationError (Association named 'alert_code' was
 not found; perhaps you misspelled it?):
 
 
 My associations look like this:
 
 report has_many alerts
 alert belongs_to :alert_code, :foreign_key = :code
 
 I am trying to get the first report whose alerts belongs to alert_code
 whose name is inside virtual fence. So there are 3 associations
 here. Trying to establish the connection.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.
 
 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] Disabling ActiveRecord type column subclassing

2013-02-19 Thread Rob Biedenharn
On Feb 18, 2013, at 7:01 PM, Jaime B. wrote:

 MichaelLatta wrote in post #227241:
 The 'type' method is a Ruby method for the class of an object.
 
 This is not a Ruby method.  This is part of ActiveRecord, and is used by
 Rails to manage single-table inheritance.

While it is true that 'type' is not a method in Ruby 1.9, it was in earlier 
versions:

irb1.8.7 1.type
(irb):1: warning: Object#type is deprecated; use Object#class
#1.8.7 = Fixnum

It is something to keep in mind whenever looking at older code.

-Rob

 
 I'm adding a solution for future askers. This applies to Rails 3:
 
 class ExampleModel  ActiveRecord::Base
  set_inheritance_column do
'disabled'
  end
 end
 
 
 This changes the name of the column that ActiveRecord looks for, to use
 for STI.  As long as you pick something that doesn't actually match any
 of your column names, it has the effect of disabling inheritance
 altogether.
 
 -- 
 Posted via http://www.ruby-forum.com/.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.
 
 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] Select and inner join

2013-02-15 Thread Rob Biedenharn

On Feb 15, 2013, at 10:12 AM, Colin Law wrote:

 On 15 February 2013 10:05, Lorenz Blackbird li...@ruby-forum.com wrote:
 I have a many-to-many relationship in my course model in this way:
 
 has_many :course_paragraphs
 has_many :paragraphs, :through = :course_paragraphs
 
 I use an inner join to select the paragraphs of my course:
 
 Paragraph.joins(:course_paragraphs = :course)
 .where('course_paragraphs.course_id' = @course.id)
 
 You don't need to do that.  If you have a course in @course then its
 paragraphs are just @course.paragraphs.  It is rare to have to use
 joins when working with Rails if you have got the associations right.
 
 
 This works, but I want to select an array containing only the ids of
 paragraphs.
 
 I think this should work.
 @course.paragraphs.select( :id )
 
 Colin

ActiveRecord actually gives you a method for exactly this:

@course.paragraph_ids

-Rob

 
 
 By this solution I get an error:
 
 @p_ids = Paragraph.select(:id)
  .joins(:course_paragraphs = :course)
  .where('course_paragraphs.course_id' = @course.id)
 
 Mysql2::Error: Column 'id' in field list is ambiguous: SELECT id FROM
 `paragraphs` INNER JOIN `course_paragraphs` ON
 `course_paragraphs`.`paragraph_id` = `paragraphs`.`id` INNER JOIN
 `courses` ON `courses`.`id` = `course_paragraphs`.`course_id` WHERE
 `course_paragraphs`.`course_id` = 1
 
 By this solution, the array contain hexadecimal values:
 
 @p_ids = Paragraph.select('paragrahs.id')
  .joins(:course_paragraphs = :course)
  .where('course_paragraphs.course_id' = @course.id)
 
 Where in my problem?
 
 Thanks to all.
 
 --
 Posted via http://www.ruby-forum.com/.
 
 --
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.
 
 
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-talk+unsubscr...@googlegroups.com.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.
 
 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] can't create record with id

2013-01-31 Thread Rob Biedenharn
tl;dr Yes, you /can/ even if Colin's advice is good (AND I agree with him!)
customer = Customer.new(other_attributes_here) {|c| c.id = user.id }
customer.save

On Jan 31, 2013, at 11:01 AM, Nishan T. wrote:

 I'm migrating the tables with existing data
 I've users table and all other tables contains the user_id column and
 now i need seperate the users into two (users  customers) tables
 So i need to migrate the new customers table with existing users records
 where the user type with customer
 
 I need to create a customers table and set the id of users records with
 user type as customer,
 which will be easy instead of migrating many of other tables(which is
 used only by customers) by checking every record with user's user type
 and assign the new id of customers table.
 
 My tables should looks like
 
 users table:
 
id  |name   |   ...
   --
1  |aaa|  ...
2  |bbb|  ...
4  |ddd|  ...
6  |fff|  ...
 
 customers table
 
id   |name  |  ...
   ---
3  |ccc  |  ...
5  |eee  |  ...
7  |ggg  |  ...
 
 When i'm migrating users existing data, I can't assign the id of user as
 customer's primary id

Well, what you can't do is use mass assigment to set the id of an 
ActiveRecord model.

You can, however, set the id on a new record and it will be honored if the 
database doesn't forbid it. (For example, if that primary key value already 
existed.)

 
 In my migration file
 
  def up
create_table(:customers) do |t|
  t.string :name
end
 
User.joins(:user_type).where(:user_type = {:type_name =
 'customer'}).find_in_batches(:batch_size = 100){ |users|
   users.each {|user|
  customer = Customer.new
  customer.id = user.id
  customer.name = user.name
  customer.save(:validate = false)
   }
   }
  end
 
 Also tried
 
  Customer.create!(:id = user.id) instead of save method
 
 And
 
  INSERT INTO customers(id, name) VALUES(#{user.id}, #{user.name})
 
 Finally all ended with same error
 
 Error: Called id for nil, which would mistakenly be 4 -- if you really
 wanted
 the id of nil, use object_id
 
 Is this correct?
 
 Is there any way to assign the primary id ?
 
 Please anyone explain how to do this?

There's even a block form of ActiveRecord.new that passes in the newly 
initialized object.

customer = Customer.new(:name = user.name) {|c| c.id = user.id }
customer.save(:validate = false)

Since you already have a user_type, it seems like you're at least halfway to 
being STI (Single-Table Inheritance) anyway.

Couldn't you have:

class Customer  User
end

Then you'd have a `type` attribute (column) in the users table which would hold 
the class name represented by that row of data. (which could be User or could 
be Customer)

Then you can say:
  r = User.find_by_name('ccc')
and r will hold an instance of the Customer class.

-Rob

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] Help displaying text

2013-01-28 Thread Rob Biedenharn

On Jan 27, 2013, at 3:04 PM, Hassan Schroeder wrote:

 On Sun, Jan 27, 2013 at 11:31 AM, Dave Castellano li...@ruby-forum.com 
 wrote:
 
 @formatted_question[:a] contains text with HTML markup.  I want to
 display it in a field so I can control its vertical and horizontal size
 on the page. When it is displayed on the page now, rather than
 interpreting the HTML, it is output into the text field as a string with
 all HTML tags showing.  What am I doing wrong??
 
 Misusing a form element :-)
 
 div id = A
%= text_area_tag id=cka,(@formatted_question[:anno_a]) %
 /div
 
 That's the way a text area works; if you want to control display size,
 use CSS to size the appropriate block-level container (e.g. div, p).
 
 -- 
 Hassan Schroeder  hassan.schroe...@gmail.com
 http://about.me/hassanschroeder
 twitter: @hassan

Also, you need to indicate that the contents should not be escaped, but 
delivered as-is to the page:

div id=cka
  %=raw @formatted_question[:anno_a] %
/div

Note the ERB tag begins %=raw That 'raw' is 
http://apidock.com/rails/ActionView/Helpers/OutputSafetyHelper/raw and will 
send the actual contents, i.e., the HTML, to the page.

-Rob

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] Cucumber issues when generating a new rails app.

2013-01-22 Thread Rob Biedenharn
On Jan 22, 2013, at 4:12 PM, Craig White wrote:
 On Jan 21, 2013, at 1:15 PM, Osifo Anosike wrote:
 Андрей Большов asnow@gmail.com wrote in post #1093053:
 What about:
 rake -T
 rake --version
 
 in common rake always print out some results, try run your command with
 `--trace`. If you have blank output for `rake -T` and got output `rake
 --version` then my guess is that you have `exit` somewhere in you
 app(try
 see in rakefile)
 
 
 , 21  2013 ., 19:01:23 UTC+4  Ruby-Forum.com
 User :
 
 
 Thanks a  lot! I ran with rake -t (this time from the root of my 
 cucumber features directory), what i got was: rake aborted! You have 
 already activated rake 10.0.3 but your gem file requires 10.0.2 run 
 bundle exec may resolve this.
 I ran bundle exec, but still  the same error. I followed the stack 
 trace, but could not understand the line of code pointed to.
 
 Please permit my being amateur, and thanks in anticipation for your 
 reply!
 
 probably the best thing to do is start doing everything the Rails 3 way...
 
 # from command line prompt
 
 #install locally bundled gems in your app first
 #inspects Gemfile and writes Gemfile.lock
 bundle install
 
 #prefix all rake commands with 'bundle exec' to use locally bundled gems
 bundle exec rake -T
 bundle exec rake db:migrate
 bundle exec rake cucumber:ok
 
 You should get the idea
 
 Craig

But before you do all that typing, perhaps just put ./bin at the front of you 
PATH and run bundler like:

  bundle install --path vendor --binstubs bin

Then those binaries for the gems will be installed to ./bin/ and you won't have 
to prefix everything with `bundle exec` to get the benefit of the bundled gems.

-Rob

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] Collect value

2013-01-21 Thread Rob Biedenharn
I tend to use a method like:

module Enumerable
  # Returns a Hash keyed by the value of the block to the number times that
  # value was returned.  If you have experience with the #group_by from
  # ActiveSupport, this would be like .group_by(block).map{|k,a|[k,a.size]}
  # (except it is a Hash rather than an Array).
  def count_by
counts = Hash.new(0)
each {|e| counts[block_given? ? yield(e) : e] += 1}
counts
  end
end

$ irb -r ./enumerable
irb1.9.3 a=[ 'casual','sick','casual','sick','casual','sick','casual','sick' ] 
#1.9.3 = [casual, sick, casual, sick, casual, sick, casual, 
sick]
irb1.9.3 a.count_by
#1.9.3 = {casual=4, sick=4}

This keeps you from iterating over the source multiple times, too.

-Rob

On Jan 21, 2013, at 1:37 AM, Ashokkumar Yuvarajan wrote:

 thanks :)
 On Mon, Jan 21, 2013 at 12:06 PM, bala kishore pulicherla 
 balumc...@gmail.com wrote:
 a.count(casual)
 
On Mon, Jan 21, 2013 at 12:03 PM, Maddy ashokku...@shriramits.com wrote:
Hi Everyone,

Good Day,

a=[ 'casual','sick','casual','sick','casual','sick','casual','sick' ] 

I need to collect casual's count and sick's count like,
Caual :4
Sick :4

Thank you,

 -- 
 Attitude is a little thing that makes a big difference
 
 Thanks  Regards
 Ashokkumar.Y
 ROR-Developer
 email : ashokku...@shriramits.com
 Shriramits

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] copy common attributes

2012-12-07 Thread Rob Biedenharn

On Dec 7, 2012, at 4:11 AM, Colin Law wrote:

 On 7 December 2012 01:30, renu mehta li...@ruby-forum.com wrote:
 Hello,
 
 If I have a model A as :
 
 name
 address
 phone
 
 and model B as:
 
 name
 address
 email
 
 My first suggestion would be that maybe the database design could be
 improved.  If there are tables with common fields then possibly the
 common data should be moved to a separate table, or perhaps even the
 two original tables should be merged.  It is a nightmare trying to
 keep tables with common data in sync.
 
 Colin

I agree with Colin. However, if you have a specific need (such as data 
conversion), then you can do something like:

irb1.9.3 JudgedEvent.column_names
#1.9.3 = [id, number, name, created_at, updated_at, year, 
event_description_id]
irb1.9.3 EventDescription.column_names
#1.9.3 = [id, name, name_for_certificate, description, created_at, 
updated_at]
irb1.9.3 cols = EventDescription.column_names - %w[ id created_at updated_at ]
#1.9.3 = [name, name_for_certificate, description]
irb1.9.3 JudgedEvent.first.attributes.slice(*cols)
  JudgedEvent Load (0.8ms)  SELECT judged_events.* FROM judged_events LIMIT 
1
#1.9.3 = {name=Financial Analyst Team}

Note that there are columns in EventDescription (like 'email' in your 'B' 
above) that are not present in JudgedEvent (your 'A'), but slice'ing them 
doesn't affect the attributes hash that will be passed on to the .new method. 
The extra columns in the destination that are missing from the source are 
effectively ignored, but if the source ever expands to include any of them, 
then they will be automagically* included.

-Rob

*(no actual magic involved)

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] Error when updating with an image file

2012-12-06 Thread Rob Biedenharn
On Dec 6, 2012, at 9:11 AM, Colin Law wrote:
 On 6 December 2012 13:43, Jean-David jeandavid.co...@gmail.com wrote:
 
 Le jeudi 6 décembre 2012 13:23:58 UTC+1, Colin Law a écrit :
 On 6 December 2012 12:11, Jean-David jeandav...@gmail.com wrote:
 ...
 Thanks for the advise. Logging led me to a solution, but I don't
 really understand what's going on under the hood.
 
 Here's my solution:
 
 upload now returns this:
  return #{uploaded_io.original_filename}
 
 In create, I set:
  @lead.illustration = upload
 
 In update, this wont work. I need to set:
  params[:lead][:illustration] = upload
 and the update goes fine.
 
 After finding this out I tried to set
  params[:lead][:illustration] = upload
 instead of
 @lead.illustration = upload
 in create, and that wont work.
 
 Can you post your create and update methods as you now have them so I
 can see what you are doing.
 
 Sure, here goes :
 
  def create
@lead = Lead.new( params[:lead] )
 
@lead.illustration = upload_image
 
if @lead.save
  flash[:success] = Leaderboard successfully added.
  redirect_to @lead
else
  redirect_to root_path
end
  end
 
  def update
@lead = Lead.find_by_id( params[:id] )
 
params[:lead][:illustration] = upload_image
 
 You said that doing @lead.illustration = upload_image (presumably at
 this point) did not work.  It should do, provided that
 params[:lead][:illustration] is not present.  If it is then the value
 from upload_image will be overwritten by the value from params when
 you call  update_attributes.  Another possibility is that if the
 illustration is the only field being changed then update_attributes
 may not actually save the record (as it does not think anything has
 changed).
 
 Probably leaving it as you have it is the simplest solution.
 
 Colin

Jean-David,

Here's a bit of code from an old project of mine:

  def update
data = params[:product].delete('data') # HashWithIndifferentAccess still 
needs the actual key type to .delete
begin
  @product = Product.find(params[:id], :conditions = { :virtual = true })

  unless data.blank?  # i.e., not replacing image
content = data.read
if content.blank?
  flash[:error] = Selected upload file was empty
  redirect_to :action = 'edit'
  return
end
@product.image_size = ImageSizer.of_blob(content).size
filename = Product.get_local_image_name data.original_filename
File.open(File.join(RAILS_ROOT, 'public', filename), 'wb') do |f|
  f.write content
end
@product.image = filename
  end

  respond_to do |format|
if @product.update_attributes(params[:product])
…
  end

Note that I am removing the 'data' key from the attributes hash 
params[:product] so that it isn't used in the .update_attributes call later. 
Perhaps you need to remove the 'illustration' since you've already handled that 
portion of the update.

If you know that the illustration is changed, but ActiveRecord doesn't, then 
perhaps you need to call @lead.illustration_will_change! to inform AR that the 
attribute is dirty and needs to be written out.

-Rob

 
 
if @lead.update_attributes( params[:lead] )
  flash[:success] = Leaderboard successfully updated.
  redirect_to @lead
else
  render action: edit
end
  end
 
 
  def upload_image
if params[:lead][:illustration]
  uploaded_io = params[:lead][:illustration]
 
  File.open(Rails.root.join('app', 'assets', 'images',
 uploaded_io.original_filename), 'wb') do |file|
file.write(uploaded_io.read)
  end
 
  return #{uploaded_io.original_filename}
end
  end
 
 
 
 
 Colin
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To unsubscribe from this group, send email to 
 rubyonrails-talk+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.
 
 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] Ajax test not working

2012-10-26 Thread Rob Biedenharn

On Oct 25, 2012, at 4:32 PM, Jason Walsh wrote:

 webber han wrote in post #1081214:
 Jason Walsh wrote in post #1080993:
 Am having real probs trying to use Ajax with my Rails app. I have set up
 a test as
 
 follows:
 
 in javascript file:
 
 window.onload = function() {
$('#test').bind('ajax:success', function() {
alert(success);
};
 }
 in view:
 
 %= link_to test, { :action = :getDiagram }, :remote = true, :id =
 test %
 in controller:
 
 def getDiagram
 
 end
 
 Now I know this looks odd with the empty controller action, but I would
 expect this code to just show a popup window with 'success' and leave
 the current page loaded when the link is clicked? Instead i get the
 missing template message like its trying to load a page synchronously
 rather than using ajax?
 
 Can anyone get my test to work? Do I need to upgrade or add a gem file?
 
 Thanks in advance
 
 Jason
 
 What I have noticed is that
 1. The javascript syntax is not correct
 2. You didn't specify a controller from the link
 3. It is probably make more sense to test with Json response using
respond_to :json
respond_with { :status = 'okay' }
 
 Thanks Webber
 
 1. Noticed the missing bracket and fixed.
 2. Have set a route as follows:
 match '/getdiagram', :to = 'prosesses#getDiagram'
 It seems to be executing the right controller/action from the error 
 message i get
 3. Tried that but get:
 c:/Users/Jason/rails_projects/procstor/app/controllers/prosesses_controller.rb:123:
  
 syntax error, unexpected tASSOC, expecting '}'
respond_with { :status = 'okay' }
 ^

The parser sees this line as a method with a block and then the = is confusing 
(not allowed there, it isn't in a Hash)

Either of these changes will do what you expect:

respond_with({ :status = 'okay' })# no longer looks like a block
respond_with   :status = 'okay'   # must be a hash literal
respond_with(  :status = 'okay'  )# must be a hash literal

Although the value for :status might need to be 'OK' or 200 rather than 'okay' 
and you need a respond_to in the controller.
http://apidock.com/rails/ActionController/MimeResponds/respond_with

-Rob

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] sum decimals

2012-10-26 Thread Rob Biedenharn

On Oct 26, 2012, at 8:18 AM, Werner wrote:

 I have a column hours which I want to sum up the decimals
 
 Week.sum('hour')= 22.5
 
 But I want to select by project_id not the hole table.
 Week.find_all_by_project_id(@project.id, :select = workhour).sum  
 #undefined method `+' for #Week hour: #BigDecimal:7fd68b358400,'0.0',9(18)
 
 I cant find anything ...some help would be great.

You left the argument out of the .sum (i..e, .sum('hour') on the second one)

I think that you just need this:

Week.where(project_id: @project_id).sum('hour')


-Rob

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] How to configure PostgreSQL's test database before testing?

2012-10-24 Thread Rob Biedenharn
RAILS_ENV=test rake db:migrate

Or you might have to specify:
RAILS_ENV=test rake db:migrate:up VERSION={put your migration number here}

It's likely that the normal db:test:prepare task doesn't support these 
extensions.

-Rob

On Oct 24, 2012, at 6:08 AM, David M wrote:

 My website uses PostgreSQL and its full-text search. For that to work, I need 
 to execute some configuration queries in order to configure some full-text 
 search extensions.
 
 This is what I have written in my seeds.rb file to configure the development 
 database:
 
 ActiveRecord::Base.connection.execute(CREATE EXTENSION unaccent;)
 ActiveRecord::Base.connection.execute(ALTER TEXT SEARCH DICTIONARY unaccent 
 (RULES='unaccent');)
 ActiveRecord::Base.connection.execute(CREATE TEXT SEARCH CONFIGURATION es ( 
 COPY = spanish );)
 ActiveRecord::Base.connection.execute(ALTER TEXT SEARCH CONFIGURATION es
   ALTER MAPPING FOR hword, hword_part, word
   WITH unaccent, spanish_stem;)
 This works perfectly in develpment.
 
 Now I want to run some search tests, but when I execute my functional tests, 
 I get an error saying that the extension is not configured:
 
 ActiveRecord::StatementInvalid: PG::Error: ERROR:  function unaccent(text) 
 does not exist
 So I assume I have to do the same that I did for development, but for the 
 test environment.
 
 How can I do it in a clean way?
 
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To unsubscribe from this group, send email to 
 rubyonrails-talk+unsubscr...@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msg/rubyonrails-talk/-/pVLjZCgazGcJ.
 For more options, visit https://groups.google.com/groups/opt_out.
  
  

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] Why Heroku so slow?

2012-10-15 Thread Rob Biedenharn
On Oct 15, 2012, at 8:10 PM, Martin G. wrote:

 Dries Steenhouwer wrote in post #1054162:
 Adrian Caceres wrote in post #1044103:
 While on the subject does anyone know what heroku's timeout is before it
 brings down an app?
 
 It will bring your app down after 1 hour of inactivity. Our problem was
 also that the first request takes a lot of time because the application
 has to start-up again.
 
 We found a nice solution ( http://www.wekkars.com ) that just does what
 we want, keep our application alive.
 
 Isn't this like pooing in your own nest?
 
 The reason that apps are taken down is to share resources with apps that 
 need them.
 
 If everyone pings their apps, the resource usage will (I am guessing?) 
 skyrocket, and we would either kiss goodbye to free services like 
 Heroku, or all suffer them getting slow when we need them.
 
 I'm open to hearing why I'm wrong, but on face value this looks sick...

The other solution is, of course, to scale to more than 1 web dyno.

https://devcenter.heroku.com/articles/dynos#dyno-idling

Apps that have more than 1 web dyno running are never idled out. Workers dynos 
are never idled out.

The goal should be to have monetized your app such that it makes sense to pay 
for some of the scalability that the Heroku platform makes possible.

Even Wekkars is setting themselves up to become a paid service. Then you'll 
have to weight the cost of the service that keeps your free service from idling 
against the cost of a service that doesn't get idled.

-Rob

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] dup/clone and taintedness

2012-10-08 Thread Rob Biedenharn
Taintedness refers to a default lack of trust in a value that was obtained from 
an unknown source. (Typically user input of some kind.)

http://www.ruby-doc.org/docs/ProgrammingRuby/html/taint.html

http://en.wikipedia.org/wiki/Taint_checking

-Rob

On Oct 7, 2012, at 9:54 PM, John Merlino wrote:

 I was reading this:
 
 these methods allocate a new instance of the class of the object on
 which they are invoked. They then copy all the instance variables and
 the taintedness of the receiver object to the newly allocated object.
 
 What does it mean taintedness?
 
 thanks for response
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To unsubscribe from this group, send email to 
 rubyonrails-talk+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.
 
 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] Array value to get except first two values

2012-09-15 Thread Rob Biedenharn
And, of course, you can just you plain 'ol Ruby for this too:

a = [1,2,3,4,5]
a[2..-1] # = [3,4,5]

%w[ a b c d e ][3..-1] #= ['d', 'e']

-Rob

On Sep 15, 2012, at 6:25 AM, Yong Gu wrote:

 If you are using Rails, 
 
 %w( a b c d ).from(0)  # = %w( a b c d )
 %w( a b c d ).from(2)  # = %w( c d )
 %w( a b c d ).from(10) # = %w()
 %w().from(0)   # = %w()
 
 On Sep 15, 2012, at 6:21 PM, Maddy wrote:
 
 Hi folks,
 
 In an array value i need to find except first two values,
 
 example:
 [1,2,3,4,5,6,7,8 ]
 
 in that i need to get values except [1,2].
 
 How can i get it from this array??
 
 please advise
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To unsubscribe from this group, send email to 
 rubyonrails-talk+unsubscr...@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msg/rubyonrails-talk/-/10r_aye1o4IJ.
 For more options, visit https://groups.google.com/groups/opt_out.
  
  
 
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To unsubscribe from this group, send email to 
 rubyonrails-talk+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.
  
  

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] embedded font

2012-08-14 Thread Rob Biedenharn

On Aug 14, 2012, at 5:32 AM, phoe san wrote:

 I want to add custom fonts in my rails project.
 
 fonts is in assets/stylesheets folder.
 In my Css .  I declare font-face :
 
 @font-face
 {
 font-family: Zawgyi-One;
 src: url(/assets/stylesheets/Zawgyi-One.ttf);
 }.

src: url('Zawgyi-one.ttf');

that's all you need to find the file.
Alternatively, '/assets/Zawgyi-one.ttf' but not with the stylesheets/ subdir 
specified. That's just how the asset pipeline searches.

-Rov

 
 ttf is not ok @ ruby on rails ?
 
 How I do ?
 
 Regards,
 
 Phoesan
 
 -- 
 Posted via http://www.ruby-forum.com/.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To unsubscribe from this group, send email to 
 rubyonrails-talk+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.
 
 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] I18n.t('countries.NO') broken?

2012-04-02 Thread Rob Biedenharn
There are optimizations in YAML for YES and NO.  Define it this way:

en:
  countries:
DE: Germany
NO: Norway
US: USA

and it should work for you.

-Rob

On Mar 31, 2012, at 7:19 AM, Sven Schwyn wrote:

 Hi
 
 I've tried this on a virgin Rails 3.2.2 app. If you put the translations
 for country names in the locale file using the 2 letter ISO code, it
 looks something like this:
 
 en:
  countries:
DE: Germany
NO: Norway
US: USA
 
 This works fine - but for Norway :-)
 
 I18n.t :'countries.DE'# = Germany
 I18n.t :'countries.NO'# = translation missing: en.countries.NO
 
 Case doesn't matter, the same happens with :'countries.no'.
 
 Any idea what could be the cause for this problem?
 
 Thanks!
 
 -- 
 Posted via http://www.ruby-forum.com/.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To unsubscribe from this group, send email to 
 rubyonrails-talk+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/rubyonrails-talk?hl=en.
 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] How to encode (.) Dot in url Rails

2012-01-20 Thread Rob Biedenharn

On Jan 20, 2012, at 7:38 AM, Loganathan Sellapa wrote:

 Hi All,
 I am having routes like below to delete/list an user.
 
 map.connect 
 'developer/:user_name/delete',:controller=developers,:action=delete,:method=:delete
 
You probably need to keep the '.' from being treated as a separator (like for a 
format):

:requirements = { :user_name = /.*/ }

-Rob
 map.connect 
 'developer/:user_name/list',:controller=developers,:action=list,:method=:get
 
 While listing the user by encoding the Dot with %2E, i can see the success 
 response http://localhost:3000/developer/testuser%2Ehu/list
 
 But While trying to delete the user who containing the Dot(.), throws 404 
 error.
 
 http://localhost:3000/developer/testuser%2Ehu/delete , thanks in advance
 
 regards,
 Loganathan

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] formatting a date string

2012-01-18 Thread Rob Biedenharn

On Jan 17, 2012, at 8:26 PM, John Merlino wrote:

 Hey all,
 
 
 I have 90 records in database with this kind of format: 2011-05-10
 11:23:15
 
 So they are all 2011-05-10 but have different times.
 
 User enters two dates, and just in case the two dates are the same, I
 want to ensure I grab all records that span entire day.
 
 So I do this:
 
 unit.reports.reports_for(Date.parse('5/10/2011').beginning_of_day,Date.parse('5/10/2011').end_of_day)
 
 But it returns empty result:
 
 = []
 
 reports_for scope looks like this:
 
   scope :reports_for, lambda { |start_date, end_date|
 where(time between ? and ?, start_date, end_date)
   }
 
 
 Problem is the sql looks like this:
 
 SELECT reports.* FROM reports WHERE (reports.unit_id = 1113) AND
 (time between '2011-10-05 00:00:00.00' and '2011-10-05
 23:59:59.99') ORDER BY time desc LIMIT 20 OFFSET 0

Have you noticed that these are 2011-10-05 and you said in the first sentence 
2011-05-10.

Depending on which version of Ruby, a/b/ where both a=12 and b=12, 
sometimes a is the month and sometimes b is the month.

Your first issue is parsing the date format as input from the user.

Take a look at Date#strptime

irb(main):003:0 Date.strptime('5/10/2011', '%m/%d/%Y').to_s
= 2011-05-10
irb(main):004:0 Date.strptime('5/10/2011', '%d/%m/%Y').to_s
= 2011-10-05


 
 Right now the user input looks like this:
 
 unit.reports.reports_for('2011/10/05','2011/10/06')
 
 But I want it to be in this format:
 
 unit.reports.reports_for('2011/05/10','2011/06/10')
 
 thanks for response
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To post to this group, send email to rubyonrails-talk@googlegroups.com.
 To unsubscribe from this group, send email to 
 rubyonrails-talk+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/rubyonrails-talk?hl=en.
 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] belongs_to and order

2011-12-09 Thread Rob Biedenharn

On Dec 9, 2011, at 2:28 PM, Fresh Mix wrote:

 Two tables:
 Users (id, username)
 Books (id, name, user_id)
 
 User has_many :books
 and
 Book belongs_to :user
 
 How can I order Books by username?
 
 @books = Book.all.order(user.username) 

@books = Book.includes(:user).order('users.username').all

-or-

@books = Book.includes(:user).all.sort_by {|book| book.user.username }


the first gets the database to return the books in the username order

The second gets the books as ruby objects, then uses the sort_by method to do 
the ordering.

-Rob

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] one-to-one relationship

2011-12-01 Thread Rob Biedenharn


On Dec 1, 2011, at 5:01 PM, Everaldo Gomes wrote:


I think it's fine.

Best Regards,
Everaldo

On Thu, Dec 1, 2011 at 7:59 PM, Erwin yves_duf...@mac.com wrote:
Is it wrong to use a beings_to on both side of a one-to-one
association ?

User
belongs_to :account  so I have an account_id field

Account
belongs_to :owner, :class_name = 'User', :foreign_key = 'user_id'

I can get   user.account and   account.owner
It runs, but I wonder about any collateral effect...

thanks for your feedback


Which one do you create first? What foreign key value does it get? Do  
you always do the create/create/update in a transaction?


Do you ever (ever!) have one without the other?


class User  ActiveRecord::Base
  has_one :account
end

class Account  ActiveRecord::Base
  belongs_to :owner, :class_name = 'User', :foreign_key = 'user_id'
end

I think that current versions of ActiveRecord have the right default  
for the foreign key (which is the _id after the class name rather than  
the association name), but specifying it works just fine, of course.


-Rob

Rob Biedenharn  
r...@agileconsultingllc.com http://AgileConsultingLLC.com/
r...@gaslightsoftware.com   http://GaslightSoftware.com/

--
You received this message because you are subscribed to the Google Groups Ruby on 
Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Re: Ruby on Windows -- *AVOID* running RoRails on Windows!

2011-11-16 Thread Rob Biedenharn


On Nov 16, 2011, at 5:43 AM, James wrote:


Since this question seems to get asked every now and then, I thought
I'd just chime in...

I've been developing happily on Windows for the last 3 years. Every
now and then there might be a small issue, but otherwise it hasn't
been as painful as many would have you believe. I do have an Ubuntu
virtual machine that I play around on as well, but you can totally get
by using Windows. The only limitation is that there is a lack of
something like RVM for Windows (unless I've missed something). So if
you're dealing with rails apps that require you chopping and changing
between versions of Ruby, you'll want to look at that Ubuntu virtual
machine.


You've missed pik
https://github.com/vertiginous/pik





(but I develop on Mac OSX so I've never used it)

-Rob

Rob Biedenharn  
r...@agileconsultingllc.com http://AgileConsultingLLC.com/
r...@gaslightsoftware.com   http://GaslightSoftware.com/

--
You received this message because you are subscribed to the Google Groups Ruby on 
Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] what a disappointing evening!

2011-11-13 Thread Rob Biedenharn

On Nov 13, 2011, at 11:08 AM, Colin Law wrote:

On 13 November 2011 15:55, tuo zhu li...@ruby-forum.com wrote:
hey guys..  I've been struggling trying to install rails_admin for  
the

whole evening and I'm now considering killing myself instead :(
my Gemfile are like this (copied from my original rails directory,  
with

rail_admin git added):

source 'http://rubygems.org'
gem 'rails', '3.1.1'
gem 'sqlite3'
gem 'rails_admin', :git = 'git://github.com/sferik/rails_admin.git'
group :assets do
 gem 'sass-rails',   '~ 3.1.4'
 gem 'coffee-rails', '~ 3.1.1'
 gem 'uglifier', '= 1.0.3'
end
gem 'jquery-rails', '~ 1.0.16'


You are specifically asking for 1.0.16 here, change it to 17 or
possibly remove the number entirely.

Colin



Not exactly.  The '~' version predicate is like shorthand:

'~ 1.0.16'
is equivalent to
'= 1.0.16', ' 1.1'

When you add that to '~ 1.0.17', you end up with:
'= 1.0.17', ' 1.1'

So jquery-rails 1.0.17 should be OK.

Perhaps you need to do:

bundle update jquery-rails

To allow a version different than 1.0.16 to be installed which is  
consistent with all the constraints.


-Rob

Rob Biedenharn  
r...@agileconsultingllc.com http://AgileConsultingLLC.com/
r...@gaslightsoftware.com   http://GaslightSoftware.com/

--
You received this message because you are subscribed to the Google Groups Ruby on 
Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] how to use mutiple yields

2011-11-12 Thread Rob Biedenharn

On Nov 12, 2011, at 7:30 AM, Michael Pavling wrote:

On 12 November 2011 04:38, Nike Mike li...@ruby-forum.com wrote:

In my layout, i have mutiple layouts.
Is there any way to reduce to a single line.Currently my layout likes
this


If you *really* want to (though I don't know why you would...)

% [:head, :foot, :bottom].each do |to_yield| %%=yield to_yield %  
%end%


Although strictly, that's still three lines...

How about

%=yield :head%%=yield :foot%%=yield :bottom%

;-)


Or just:

%= [ :head, :foot, :bottom ].map {|section| yield section } %

Though it makes be wonder how/why the associated content_for blocks  
are not together already making this a bit moot.


-Rob




How to call this in a single method


You could also move those three lines into a partial, and render that
with a single line in your layout.




Rob Biedenharn  
r...@agileconsultingllc.com http://AgileConsultingLLC.com/
r...@gaslightsoftware.com   http://GaslightSoftware.com/

--
You received this message because you are subscribed to the Google Groups Ruby on 
Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Re: functional testing API: GET versus POST?

2011-11-07 Thread Rob Biedenharn

On Nov 6, 2011, at 4:35 PM, Grary Stimon wrote:

   request = 4_000_000
   post :loan, {:loan_request=request, :format = :json}

...finally the test log of the request is...

 Processing by Sec223fAcquisitionController#loan as JSON
The influence of the :format=:json bit is ...^^here^^.  If you  
compare this to other requests, you'll probably see that they are as  
HTML



 Parameters: {loan_request=400}
Completed 500 Internal Server Error in 28ms


What bugs me here is that I don't see the JSON format appear anywhere
above. I understand why the parser would choke on
'loan_request=400', because it's not JSON.

Grar



the as JSON is that the response is desired in JSON format, not that  
the request parameters are in that format. You can see from the log  
output that the parameter is what you expect:

 params[:loan_request] == 400

What does the rest of the loan action look like?

-Rob

Rob Biedenharn  
r...@agileconsultingllc.com http://AgileConsultingLLC.com/
r...@gaslightsoftware.com   http://GaslightSoftware.com/

--
You received this message because you are subscribed to the Google Groups Ruby on 
Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Add an index to a form

2011-10-26 Thread Rob Biedenharn


On Oct 26, 2011, at 11:53 AM, JavierQQ wrote:


Hello,

I'm having some trouble with forms, my app allows to enter data by
using a multi-step form that has 7 steps.
There are 3 steps that may let the user to add 1 form, for example
there's a step called children
and that children has the following fields:
 * name
 * age
 * gender
but one father may have more than 1 child and I'm adding another form
with ajax by following this
http://stackoverflow.com/questions/4812003/adding-fields-dynamically-in-a-nested-model-form-in-rails-3

in the invite partial
_invite.html.erb
%= fields_for user[invites_attributes][], invite do |i| %
 li
   %= link_to(Remove, #delete, :class = delete-invite) %
   %= i.label :full_name, Full Name %
   %= i.text_field :full_name %
   %= i.label :email, Email Address %
   %= i.text_field :email %
 /li
% end %

I'm having some troubles with the first line: %= fields_for
user[invites_attributes][], invite do |i| %
What is the correct usage of that? I'm using formtastic and when I
made that line but with my fields

%= f.semantic_fields_for (user[children_attributes][], user)
do |fes| %

and I get this error

 ...  unexpected ',', expecting ')'

I hope someone can help

Thanks in advance



I think that the space after f.semantic_fields_for and the parentheses  
around the argument list are interacting to produce the error.


I think that you can probably do either fix and resolve the issue:

%= f.semantic_fields_for user[children_attributes][], user do | 
fes| %


%= f.semantic_fields_for(user[children_attributes][], user) do  
|fes| %


-Rob

Rob Biedenharn  
r...@agileconsultingllc.com http://AgileConsultingLLC.com/
r...@gaslightsoftware.com   http://GaslightSoftware.com/

--
You received this message because you are subscribed to the Google Groups Ruby on 
Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Re: Postgresql adapter not working

2011-10-06 Thread Rob Biedenharn


On Oct 6, 2011, at 9:48 AM, Peter Vandenabeele wrote:


2011/10/5 Luís de Sousa luis.a.de.so...@gmail.com
Hello again,

I managed to get rake db:create to work, it requires the creation of  
an application with the -d postgresql argument. Nevertheless, it  
throws a strange message saying that the database already exists. I  
will move onwards with the tutorial to see if it really works.


I think this issue should be made clear on the tutorial; some basic  
guidelines on which adapter to use could also be helpful.



I read you use Ubuntu (am I correct ?).

When googling for install ruby on rails ubuntu
* the first entry points to a page on help.ubuntu.com that talks  
about 8.04 and 9.04

* the second entry points to a very short description help.ubuntu.com
* the third page points to a broken page on http://wiki.rubyonrails.org/
* and then we get into private blogs, which may be OK, but are less  
authorative


I would volunteer to make a proper write-up for Ruby and Rails on  
Ubuntu 10.04

and/or 11.10 with rvm, ruby 1.9.(2|3), postgresql, etc.

Particularly I would also make clear which extra -dev Debian  
packages are needed
for native compilation when starting from a vanilla Ubuntu (32 bit  
x86) client machine

install.

That could be similar in style to what I did on my blog for Jaunty  
(9.04) a few years ago

http://vandenabeele.com/Rails-on-Ubuntu-Jaunty

My goal is to put a correct how-to in the place that is most easily  
found by newcomers

that are working on Ubuntu.

Maybe most efficient would be to update the number 1 hit that is the  
Ubuntu help Wiki.


Would this be useful, or is this problem solved and did I just not  
find the correct
pointers by googling? (in that case, I could update the wiki to  
point there or copy

the correct description on the Ubuntu help Wiki).

Thanks for your feedback,

Peter


tl;dr https://gist.github.com/1261571


At Gaslight Software, we are helping a group at a local high school  
develop a simple web application and have exactly this same situation.


We went with Ubuntu 10.04 LTS, Ruby 1.9.2, Rails 3.1, and PostgreSQL,  
but the steps should be the same.


Configuring Ubuntu 10.04 for Rails Development

http://blog.gaslightsoftware.com/post/11027905735/configuring-ubuntu-10-04-for-rails-development

Our time is limited with them so we're only sure that everything gets  
installed, but we've gotten six ubuntu workstations configured and  
next week should actually spin up a demo rails app.


-Rob

Rob Biedenharn  
r...@agileconsultingllc.com http://AgileConsultingLLC.com/
r...@gaslightsoftware.com   http://GaslightSoftware.com/

--
You received this message because you are subscribed to the Google Groups Ruby on 
Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] fubar and Gemfile.lock

2011-09-29 Thread Rob Biedenharn

On Sep 29, 2011, at 1:16 PM, Barney wrote:


Hi All,
In trying to port a working version from one computer to another
I had installed the requisites and copied over the files in the rails
project.  However one method wouldn't work and it was because the gem
involved wouldn't work with the newest rails.  After uninstalling
rails, reinstalling an earlier version and playing with DevKit, et.
al., I've managed to fubar the project so that now it even claims it
can't find rubygems.  So I'm inclined to uninstall gems, the devkit
and rails and then copy over the code again, essentially starting
over.
Question 1) what is the proper method of uninstalling those 3?
Question 2) What is the function of the file Gemfile.lock.  Should
it be copied over or will it be generated?
Thanks,
 Barney


Let me answer your 2nd question first.  The Gemfile.lock specifies the  
versions of each gem that were selected to satisfy the dependency  
graph. You should copy it over (actually, you should check it into the  
repository; you are using a code repository, right?) and then a bundle  
install will use those versions.  Without Gemfile.lock, it builds a  
new dependency graph, either with gems it finds or gems that it  
installs, and constructs a new Gemfile.lock with the results.


You can also run `bundle package` to put all the .gem files into  
vendor/cache/ (by default) which can also be kept in the repository.


Copy the Gemfile.lock over and see if `bundle install` doesn't just  
solve your problem.


-Rob

Rob Biedenharn  
r...@agileconsultingllc.com http://AgileConsultingLLC.com/
r...@gaslightsoftware.com   http://GaslightSoftware.com/

--
You received this message because you are subscribed to the Google Groups Ruby on 
Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Re: fubar and Gemfile.lock

2011-09-29 Thread Rob Biedenharn


On Sep 29, 2011, at 5:00 PM, Barney wrote:


On Sep 29, 2:30 pm, Rob Biedenharn r...@agileconsultingllc.com
wrote:

On Sep 29, 2011, at 1:16 PM, Barney wrote:


Hi All,
In trying to port a working version from one computer to another
I had installed the requisites and copied over the files in the  
rails
project.  However one method wouldn't work and it was because the  
gem

involved wouldn't work with the newest rails.  After uninstalling
rails, reinstalling an earlier version and playing with DevKit, et.
al., I've managed to fubar the project so that now it even claims it
can't find rubygems.  So I'm inclined to uninstall gems, the devkit
and rails and then copy over the code again, essentially starting
over.
Question 1) what is the proper method of uninstalling those 3?
Question 2) What is the function of the file Gemfile.lock.  Should
it be copied over or will it be generated?
Thanks,
 Barney


Let me answer your 2nd question first.  The Gemfile.lock specifies  
the

versions of each gem that were selected to satisfy the dependency
graph. You should copy it over (actually, you should check it into  
the
repository; you are using a code repository, right?) and then a  
bundle

install will use those versions.  Without Gemfile.lock, it builds a
new dependency graph, either with gems it finds or gems that it
installs, and constructs a new Gemfile.lock with the results.

You can also run `bundle package` to put all the .gem files into
vendor/cache/ (by default) which can also be kept in the repository.

Copy the Gemfile.lock over and see if `bundle install` doesn't just
solve your problem.

-Rob

Rob Biedenharn
r...@agileconsultingllc.com  http://AgileConsultingLLC.com/
r...@gaslightsoftware.comhttp://GaslightSoftware.com/


Thanks, Rob.  I'll copy over my original tomorrow morning.
Is there anything special I have to know if I still need to start over
(in terms of being careful to delete certain things that uninstall
didn't uninstall, etc.)?
Barney


The bundle install will very likely be all you need.  It will install  
additional versions of gems if the one that you got originally on the  
new machine is different. Then you will almost certainly want to use  
`bundle install _cmd_` whenever you run a _cmd_ that needs gems to be  
sure that you're getting the right version(s).


-Rob

--
You received this message because you are subscribed to the Google Groups Ruby on 
Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Re: fubar and Gemfile.lock

2011-09-29 Thread Rob Biedenharn

On Sep 29, 2011, at 6:43 PM, Peter Vandenabeele wrote:
On Thu, Sep 29, 2011 at 11:09 PM, Rob Biedenharn r...@agileconsultingllc.com 
 wrote:


On Sep 29, 2011, at 5:00 PM, Barney wrote:

On Sep 29, 2:30 pm, Rob Biedenharn r...@agileconsultingllc.com
wrote:
On Sep 29, 2011, at 1:16 PM, Barney wrote:

Hi All,
   In trying to port a working version from one computer to another
I had installed the requisites and copied over the files in the rails
project.  However one method wouldn't work and it was because the gem
involved wouldn't work with the newest rails.  After uninstalling
rails, reinstalling an earlier version and playing with DevKit, et.
al., I've managed to fubar the project so that now it even claims it
can't find rubygems.  So I'm inclined to uninstall gems, the devkit
and rails and then copy over the code again, essentially starting
over.
Question 1) what is the proper method of uninstalling those 3?
Question 2) What is the function of the file Gemfile.lock.  Should
it be copied over or will it be generated?
   Thanks,
Barney

Let me answer your 2nd question first.  The Gemfile.lock specifies the
versions of each gem that were selected to satisfy the dependency
graph. You should copy it over (actually, you should check it into the
repository; you are using a code repository, right?) and then a bundle
install will use those versions.  Without Gemfile.lock, it builds a
new dependency graph, either with gems it finds or gems that it
installs, and constructs a new Gemfile.lock with the results.

You can also run `bundle package` to put all the .gem files into
vendor/cache/ (by default) which can also be kept in the repository.

Copy the Gemfile.lock over and see if `bundle install` doesn't just
solve your problem.

-Rob

Rob Biedenharn
r...@agileconsultingllc.com  http://AgileConsultingLLC.com/
r...@gaslightsoftware.comhttp://GaslightSoftware.com/

Thanks, Rob.  I'll copy over my original tomorrow morning.
Is there anything special I have to know if I still need to start over
(in terms of being careful to delete certain things that uninstall
didn't uninstall, etc.)?
   Barney

The bundle install will very likely be all you need.  It will  
install additional versions of gems if the one that you got  
originally on the new machine is different. Then you will almost  
certainly want to use `bundle install _cmd_` whenever you run a  
_cmd_ that needs gems to be sure that you're getting the right  
version(s).


I presume this last sentence has a typo. I presume you intended to  
say ...  use `bundle exec _cmd_` whenever  ...


Like this:

$ bundle install rake environment  # probably incorrect
install was called incorrectly. Call as bundle install.
$ bundle exec rake environment # this is you first test that should  
pass


HTH,

Peter


Ah, yes. Thank you for catching that, Peter.
-Rob



-Rob

--
Peter Vandenabeele
gsm: +32-478-27.40.69
e-mail: pe...@vandenabeele.com
http://twitter.com/peter_v


--
You received this message because you are subscribed to the Google Groups Ruby on 
Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] includes from a table that does not have an id field

2011-09-29 Thread Rob Biedenharn

On Sep 29, 2011, at 8:56 PM, maskiran wrote:


I have the following tables

create table files(id int ai pk, name varchar(255)
create table admins (file_id int, user_id int)
create table users (id int ai pk, name varchar(16),email varchar(255))


And presumably classes like:

class File
  has_many :admins
  has_many :users, :through = :admins
end
class Admin
  belongs_to :file
  belongs_to :user
end
class User
end



I want to get all the admin user names and emails of a given file. Say
for file 1


File.find(1).users

or

File.where(:id = 1).users



Admin.where(:file_id=1).includes(:user). it works very good. Now I
want to sort the admins on the usernames


Then add and .order('users.name') to the query.

Alternatively, you could always get the users in that order:

class File
  has_many :admins
  has_many :users, :through = :admins, :order = 'users.name'
end



Admin.where(:file_id=1).include(:user).order('users.name'). this
shows an sql query with an empty column and so bails out. here's the
query I got on the console

SELECT `admins`.`` AS t0_r0, `admins`.`file_id` AS t0_r1,
`admins`.`user_id` AS t0_r2, `users`.`id` AS t1_r0, `users`.`name` AS
t1_r1 FROM `admins` LEFT OUTER JOIN `users` ON `users`.`id` =
`admins`.`user_id` WHERE `admins`.`file_id` = 1 ORDER BY users.name

The first column name is being taken as empty (immediately after the
select).

Is this a bug? I don't want to have id field in the admins table as
that's not useful. How do I write a AR query to sort out this issue

thanks
Kiran



You should not need an `id` on the admins table, but you almost  
certainly want to have an index on each of the `file_id` and `user_id`  
columns.


-Rob

Rob Biedenharn  
r...@agileconsultingllc.com http://AgileConsultingLLC.com/
r...@gaslightsoftware.com   http://GaslightSoftware.com/

--
You received this message because you are subscribed to the Google Groups Ruby on 
Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



  1   2   3   4   5   >