[Rails] [ANN] Rails 3.1.0.rc8

2011-08-28 Thread Santiago Pastorino
Hi everyone,

Rails 3.1.0.rc8 has been released (we've an issue with rc7).  This is
the final release candidate. Please give it a try, it's our last
chance to fix regressions and severe issues. We will be releasing
final 3.1.0 next August 30th.

## CHANGES

Check the CHANGELOG file of each framework to see what we've changed.

You can find an exhaustive list of changes on
[github](https://github.com/rails/rails/compare/v3.1.0.rc6...v3.1.0.rc8).
 Along with the [closed issues marked for
v3.1.0](https://github.com/rails/rails/issues?sort=created&direction=desc&state=closed&page=1&milestone=1).

You can also see issues [we haven't
closed](https://github.com/rails/rails/issues?sort=created&direction=desc&state=open&page=1&milestone=1).

A comprehensive CHANGELOG will be announced when 3.1.0 final is released.

Thanks!

-- 
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: Re: :dependent => :destroy with nonstandard :foreign_key?

2011-08-28 Thread Walter Lee Davis


On Aug 28, 2011, at 6:23 PM, Marnen Laibow-Koser wrote:


Um, thanks...?  I don't know whether to feel flattered or put down. :D


I hope you feel flattered, at least that was what I was aiming for. I  
did very much enjoy your posts, and learned quite a lot from them. I  
hope you can find a middle path between saint-like "suffer fools  
gladly" and and "getting too upset" to start answering again. I'm sure  
you have quite a lot more to teach me, and others here.


Walter

--
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.



[Rails] Re: Error with errors

2011-08-28 Thread 7stud --
Jeroen van Ingen wrote in post #1018925:
> The way you want to display the errors looks cumbersome to me. But maybe
> you have a good reason to do it this way (Actually I'm curious why you
> do it this way).
>

http://railscasts.com/episodes/211-validations-in-rails-3

-- 
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.



[Rails] Re: Error with errors

2011-08-28 Thread 7stud --
Neil Bye wrote in post #1018907:
> I have an app which I have upgraded to rails3. It is working fine but
> for displaying error messages.
>
> Take i.e. new.html.erb. In the model I have several validations that
> work, they do not create a user if the entries are wrong. On submission
> it dutifully returns to new.html.erb but WITHOUT the nice red error
> messages.
>
> I have been using
>
>   <% if @user.errors.any? %>
> 
>   <%= pluralize(@user.errors.count, "error") %> prohibited this
> user from being saved:
>
>   
>   <% @user.errors.full_messages.each do |msg| %>
> <%= msg %>
>   <% end %>
>   
> 
>   <% end %>
>
> but that doesn't help.
>

1)  Is that a partial?  If so, are you actually including it in a view 
somewhere, e.g.

<%= render './error_messages' %>

2) Is the partial named correctly, e.g.: '_error_messages.html.erb ?

3) I'm not quite sure what the directory rules are for rails, but is the 
partial in a directory that can be accessed by multiple controllers, 
e.g. app/views/shared/_error_messages.html.erb?


> Of course, you would have to have I think the problem may be deeper. Do you 
> know
> what files are used when displaying the errors? Where does the error
> variable come from?.

It's 'errors' not 'error', and @user is an ActiveRecord::Base object, so 
the errors() method must be defined in that class or one of that class's 
parent classes.

> Could it be a js problem?

Sure.  If your js says to hide any html elememts with 
id="error_explanation", then none of the error messages will be visible.

-- 
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.



[Rails] Re: Error with errors

2011-08-28 Thread 7stud --
Jeroen van Ingen wrote in post #1018925:
> Why don't you do it the 'regular' Rails way with the method
> 'f.error_messages'?
>
> Note that this method is not available in Rails 3 anymore.
> (Actually I'm curious why you
> do it this way).
>

>> I have an app which I have upgraded to rails3.

Duh.

-- 
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.



[Rails] Re: Re: Class Variable

2011-08-28 Thread 7stud --
Michael Pavling wrote in post #1018902:
> On 28 August 2011 14:55, 7stud --  wrote:
>> In addition, you shouldn't be using class variables. You can forget
>> they exist.
>
> Bwah! Hahahah!
>
> What tosh...
>

Live and learn.

-- 
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.



[Rails] Re: Re: :dependent => :destroy with nonstandard :foreign_key?

2011-08-28 Thread Marnen Laibow-Koser
Walter Davis wrote in post #1016477:
> On Aug 12, 2011, at 4:07 PM, Colin Law wrote:
>
>> On 12 August 2011 18:35, Fearless Fool  wrote:
>>> Resurrecting an old thread because it has a useful lesson:
>>>
>>> Marnen Laibow-Koser wrote in post #927576:
 [snip]
>>
>> O Marnen, Marnen! wherefore art thou Marnen?
>>
>
> Fun fact: "wherefore" means "why". [1]

Indeed.

>
> I wonder where Marnen went, but I never wondered why he was Marnen. I
> did appreciate his unique brand of scorched earth and incredibly
> precise answers.

Um, thanks...?  I don't know whether to feel flattered or put down. :D

Anyway, I'm still around.  I just haven't been posting much.  I went on 
a self-imposed vacation from posting back in January (because I was 
getting too upset to respond as nicely as I wanted to!), and never got 
back into the habit.  I'll probably be a more regular contributor again 
in the near future.

>
> Walter
>
> 1. In the famous quote, Juliet is wondering *why* Romeo is named the
> way he is; because of his name, she cannot be allowed to love him. Her
> logic, typical for Shakespeare women, is quite sound: "A rose by any
> other name would smell as sweet..."

Yup.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org

-- 
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.



[Rails] Update form after changing model with migration

2011-08-28 Thread Jose Riera
Hi *, I create a migration that modifies an object of my model. There is
any rails command for update the form of that object?

Something like: "rails update object X"

Or I have to change it manually?

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.



Re: [Rails] Best form in pulling the last two records from a dataset in active record

2011-08-28 Thread Tom Meinlschmidt

On Aug 28, 2011, at 21:04 , Hassan Schroeder wrote:

> On Sun, Aug 28, 2011 at 11:25 AM, Jeroen van Ingen  
> wrote:
>> Create a named_scope (scope in Rails 3) like this:
>> scope :secondlatestpost, :limit => 2, :order => :published_at
> 
> Or for some flexibility:
> 
> scope :latest, lambda {|number| { :order => :updated_at, :limit => number } }

just a note .. request was for LAST two records… with this order query will 
return first two records, assume use

:order => 'published_at desc'

:)

>> BlogPost.latest
> 
> then you can ask for  e.g. BlogPost.latest 2or BlogPost.latest 5
> (and with no number specified get them all in update order).
> 
> FWIW,
> -- 
> Hassan Schroeder  hassan.schroe...@gmail.com
> http://about.me/hassanschroeder
> twitter: @hassan
> 
> -- 
> 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.

-- 
===
Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache

www.meinlschmidt.com  www.maxwellrender.cz  www.lightgems.cz
===

-- 
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: Best form in pulling the last two records from a dataset in active record

2011-08-28 Thread Hassan Schroeder
On Sun, Aug 28, 2011 at 11:25 AM, Jeroen van Ingen  wrote:
> Create a named_scope (scope in Rails 3) like this:
> scope :secondlatestpost, :limit => 2, :order => :published_at

Or for some flexibility:

scope :latest, lambda {|number| { :order => :updated_at, :limit => number } }

> BlogPost.latest

then you can ask for  e.g. BlogPost.latest 2or BlogPost.latest 5
(and with no number specified get them all in update order).

FWIW,
-- 
Hassan Schroeder  hassan.schroe...@gmail.com
http://about.me/hassanschroeder
twitter: @hassan

-- 
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.



[Rails] Re: Local timezone issues

2011-08-28 Thread Frederick Cheung


On Aug 28, 7:27 pm, comopasta Gr  wrote:
> David K. wrote in post #1018917:
>
> > On Sun, Aug 28, 2011 at 8:09 AM, Frederick Cheung <
> > frederick.che...@gmail.


> I don't know for sure how Rails knows the local time (browser?) because
> I couldn't find anything in the request object that would indicate that.
> When request something locally I can see: ...for 127.0.0.1 at 2011-08-28
> 20:53:49 +0300 for example.
>
> In any case I have the part to get the timezone offset from the browser
> and I could use that info in a before filter. But the way I was reading
> the docs I thought I could save that before filter.
>
Local would mean whatever the local timezone is set to on the server
(and influenced by things like the TZ environment variable. I seem to
remember that setting is best left as :utc, using config.time_zone
(which controls the default value of Time.zone) for making your times
display in whatever timezone you need.


Fred


> A bit mixed up...
>
> --
> Posted viahttp://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.



[Rails] Re: Re: Local timezone issues

2011-08-28 Thread comopasta Gr
David K. wrote in post #1018917:
> On Sun, Aug 28, 2011 at 8:09 AM, Frederick Cheung <
> frederick.che...@gmail.com> wrote:
>
>> > ActiveSupport::TimeWithZone
>>
> When you say this, how are you determining that it 'still comes in utc'?
> From what you see on a view?
>
> Fred is right, for example on a certain app of mine the user can set
> their
> time zone so on the app controller I set 'Time.zone = ...' in a before
> filter for the user. You could set this per user or app wide.
>
>
>>

Thanks Fred and David.

I know it comes in utc because it is the same as stored in the DB. The
one I should see in the view should be that +3 hours.

I'm still confused by the wording in the documentation in
http://guides.rubyonrails.org/configuring.html

"config.active_record.default_timezone determines whether to use
Time.local (if set to :local) or Time.utc (if set to :utc) when pulling
dates and times from the database. The default is :utc for Rails,
although Active Record defaults to :local when used outside of Rails."

So if I set ActiveRecord::Base.default_timezone = :local then when
pulling the dates it should convert the UTC dates to Local. Right?

I don't know for sure how Rails knows the local time (browser?) because
I couldn't find anything in the request object that would indicate that.
When request something locally I can see: ...for 127.0.0.1 at 2011-08-28
20:53:49 +0300 for example.

In any case I have the part to get the timezone offset from the browser
and I could use that info in a before filter. But the way I was reading
the docs I thought I could save that before filter.

A bit mixed up...

-- 
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.



[Rails] Re: Best form in pulling the last two records from a dataset in active record

2011-08-28 Thread Jeroen van Ingen
Create a named_scope (scope in Rails 3) like this:
scope :secondlatestpost, :limit => 2, :order => :published_at

Then declare it as follows:
BlogPost.secondlatestpost

BTW IMHO the method name 'secondlatestpost' is a little long. I should 
take a name like BlogPost.latest

-- 
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.



[Rails] Re: iphone and android with RoR 3.x

2011-08-28 Thread Pepe Sanchez
Hi all

Finally I think that I am going to continue working with XCode and 
MonoTouch for iPhone applications

thank you for your advice

-- 
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.



[Rails] Re: How do I change the name of a label in a form?

2011-08-28 Thread Pepe Sanchez
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.



[Rails] Re: How do I change the name of a label in a form?

2011-08-28 Thread Adam
I always wondered, is there a way you can change the f.label at a
model label so regardless of where its used it always has the updated
label? is it somewhere in the localization file? or does this just
indicate for rails to have a best guess at what it is. I tried
defining them in a language file once but it never seemed to pick them
up.

On Aug 28, 1:44 pm, Noel  wrote:
>    <%= f.label "My label" %>
>
>
>
>
>
>
>
> On Sun, Aug 28, 2011 at 10:01 AM, Pepe Sanchez  wrote:
> > Hi,
>
> > Instead of having on the labels the field name I would like to change it
> > some customized values.
>
> > How can I change that ?
>
> > Regards
>
> > %= form_for(@client_workout) do |f| %>
>
> >  
> >    <%= f.label :client_name %>
> >    <%= f.text_field :client_name %>
> >  
> >  
> >    <%= f.label :trainer %>
> >    <%= f.text_field :trainer %>
> >  
> >  
> >    <%= f.label :duration_min %>
> >    <%= f.text_field :duration_min %>
> >  
> >  
> >    <%= f.label :date_of_workout %>
> >    <%= f.date_select :date_of_workout %>
> >  
> >  
> >    <%= f.label :paid_amount %>
> >    <%= f.text_field :paid_amount %>
> >  
> >  
> >    <%= f.submit %>
> >  
> > <% end %>
>
> > --
> > Posted viahttp://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 
> > athttp://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.



[Rails] Best form in pulling the last two records from a dataset in active record

2011-08-28 Thread Adam
I have a model, blog_posts which has a field "published_at". I'd like
to select the latest two blogs from that model to display on my
homepage. Not sure how to structure that though.

At the moment I have a work around that takes a slice of the data but
it keeps failing when I have nothing in the table, rather than fix
this I feel there is probably a better way to retrieve the data.

I need to select the blogs in separate calls, for example

@blog_post.latestpost, @blog_post.secondlatestpost

Thanks, Adam

-- 
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.



[Rails] Re: Is a bad practice to do this while testing with Rspec?

2011-08-28 Thread Ezequiel Schwartzman
David K. wrote in post #1018921:
> On Sun, Aug 28, 2011 at 10:29 AM, Ezequiel Schwartzman
> 
> In my book this is fine you have a list of specific examples and it
> is
> clear what you are doing. I might go further and make sure that in fact
> it
> is the email which is valid/invalid vs just checking the model (at least
> in
> the case if you are checking what should be invalid data) as another
> field
> could be the invalid one.
>
> I also like shoulda as you get helpers like:
>
>   it { should allow_value('david.n_k...@gmail.com.mx').for(:email) }
>   it { should_not allow_value('david nathan kahn at gmail dot
> com').for(:email) }


Thanks! I'm looking into shoulda now, it seems very useful! ^^

-- 
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.



[Rails] Re: Error with errors

2011-08-28 Thread Jeroen van Ingen
The way you want to display the errors looks cumbersome to me. But maybe 
you have a good reason to do it this way (Actually I'm curious why you 
do it this way).

Why don't you do it the 'regular' Rails way with f.error_messages?

Note that this method is not available in Rails 3 anymore. You have to 
use the plugin 'dynamic_form' made by the Rails Core Team I guess. For 
more information see: https://github.com/joelmoss/dynamic_form

-- 
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.



Re: [Rails] How do I change the name of a label in a form?

2011-08-28 Thread Tom Meinlschmidt

On Aug 28, 2011, at 19:44 , Noel wrote:

>   <%= f.label "My label" %>
> 

no

f.label :field, "my name"

https://github.com/rails/rails/blob/4145810150070160677df00345fe22c66e457c1c/actionpack/lib/action_view/helpers/form_helper.rb#L1179

tom

> 
> On Sun, Aug 28, 2011 at 10:01 AM, Pepe Sanchez  wrote:
>> Hi,
>> 
>> Instead of having on the labels the field name I would like to change it
>> some customized values.
>> 
>> How can I change that ?
>> 
>> Regards
>> 
>> %= form_for(@client_workout) do |f| %>
>> 
>> 
>>  
>><%= f.label :client_name %>
>><%= f.text_field :client_name %>
>>  
>>  
>><%= f.label :trainer %>
>><%= f.text_field :trainer %>
>>  
>>  
>><%= f.label :duration_min %>
>><%= f.text_field :duration_min %>
>>  
>>  
>><%= f.label :date_of_workout %>
>><%= f.date_select :date_of_workout %>
>>  
>>  
>><%= f.label :paid_amount %>
>><%= f.text_field :paid_amount %>
>>  
>>  
>><%= f.submit %>
>>  
>> <% end %>
>> 
>> --
>> 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.

-- 
===
Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache

www.meinlschmidt.com  www.maxwellrender.cz  www.lightgems.cz
===

-- 
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 do I change the name of a label in a form?

2011-08-28 Thread Noel
   <%= f.label "My label" %>


On Sun, Aug 28, 2011 at 10:01 AM, Pepe Sanchez  wrote:
> Hi,
>
> Instead of having on the labels the field name I would like to change it
> some customized values.
>
> How can I change that ?
>
> Regards
>
> %= form_for(@client_workout) do |f| %>
>
>
>  
>    <%= f.label :client_name %>
>    <%= f.text_field :client_name %>
>  
>  
>    <%= f.label :trainer %>
>    <%= f.text_field :trainer %>
>  
>  
>    <%= f.label :duration_min %>
>    <%= f.text_field :duration_min %>
>  
>  
>    <%= f.label :date_of_workout %>
>    <%= f.date_select :date_of_workout %>
>  
>  
>    <%= f.label :paid_amount %>
>    <%= f.text_field :paid_amount %>
>  
>  
>    <%= f.submit %>
>  
> <% end %>
>
> --
> 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] Is a bad practice to do this while testing with Rspec?

2011-08-28 Thread David Kahn
On Sun, Aug 28, 2011 at 10:29 AM, Ezequiel Schwartzman  wrote:

> I'm testing the validation of emails so I did the following:
>
> it 'should only allow domains names with numbers, letters, dots or
> dashes' do
>(%-\\|!"#$\%&/()=?¡;,:{}+'<>°+*[]"¬~^@áéíóú´`_ -).each_char do
> |c|
>  Factory.build(:user, :email =>
> "zequez@gm#{c}ail.com").should_not be_valid
>end
>  end
>
> Also this:
>
> ['1...@1.com',
>   '1-...@ar.com',
>   'zequez...@com.com',
>   'z_e_q_u_...@t-p.9.asd.g.r.t.a.c.com',
>   'zambu...@t-p.9.asd.g.r.t.a.c.com',
>   'zez...@com.ar',
>   '...@asd.com',
>   'z@q.z',
>   'y...@zequez.com',
>   'ca..--__ca..--__ca..--...@zequez.com'].each do |email|
>it "should allow #{email} as a valid email" do
>  Factory.build(:user, :email => email).should be_valid
>end
>  end
>
> And many similar things...
>
> Is that bad?
>

In my book this is fine you have a list of specific examples and it is
clear what you are doing. I might go further and make sure that in fact it
is the email which is valid/invalid vs just checking the model (at least in
the case if you are checking what should be invalid data) as another field
could be the invalid one.

I also like shoulda as you get helpers like:

  it { should allow_value('david.n_k...@gmail.com.mx').for(:email) }
  it { should_not allow_value('david nathan kahn at gmail dot
com').for(:email) }



>
> --
> 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.



[Rails] Is a bad practice to do this while testing with Rspec?

2011-08-28 Thread Ezequiel Schwartzman
I'm testing the validation of emails so I did the following:

it 'should only allow domains names with numbers, letters, dots or
dashes' do
(%-\\|!"#$\%&/()=?¡;,:{}+'<>°+*[]"¬~^@áéíóú´`_ -).each_char do
|c|
  Factory.build(:user, :email =>
"zequez@gm#{c}ail.com").should_not be_valid
end
  end

Also this:

['1...@1.com',
   '1-...@ar.com',
   'zequez...@com.com',
   'z_e_q_u_...@t-p.9.asd.g.r.t.a.c.com',
   'zambu...@t-p.9.asd.g.r.t.a.c.com',
   'zez...@com.ar',
   '...@asd.com',
   'z@q.z',
   'y...@zequez.com',
   'ca..--__ca..--__ca..--...@zequez.com'].each do |email|
it "should allow #{email} as a valid email" do
  Factory.build(:user, :email => email).should be_valid
end
  end

And many similar things...

Is that bad?

-- 
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.



Re: [Rails] Re: Local timezone issues

2011-08-28 Thread David Kahn
On Sun, Aug 28, 2011 at 8:09 AM, Frederick Cheung <
frederick.che...@gmail.com> wrote:

>
>
> On Aug 28, 2:56 pm, comopasta Gr  wrote:
> > Hi,
> >
> > So I store Visit records in UTC: 2011-08-28 13:23:48.714506
> > I am in timezone +3 so I can verify that the stored created at is in
> > UTC.
> >
> > Rails.logger.debug visits.last.created_at.class returns
> > ActiveSupport::TimeWithZone
> >
> > I'm using pgAdmin3 and when checking the table on the UI app you can see
> > the datatypes. Strangely there in the UI of pgAdmin3 it reads
> > "created_at timestamp without time zone". That is odd.
> >
> > Based in what I've read the data is in DB in UTC but when it pulls it
> > from the db it should convert it to local automatically.
> >
> > I am in zone +3 so I should get 16:23:48 for the record above. But it
> > still comes in UTC.
>

When you say this, how are you determining that it 'still comes in utc'?
>From what you see on a view?

Fred is right, for example on a certain app of mine the user can set their
time zone so on the app controller I set 'Time.zone = ...' in a before
filter for the user. You could set this per user or app wide.


> >
> > Any hints what could be the problem?
> >
>
> It converts the utc value from utc to whatever Time.zone is. Unless
> you're setting Time.zone elsewhere, because you've set
> config.time_zone to utc, Time.zone will be utc too. Try setting
> config.time_zone to the desired timezone (don't forget to restart your
> app)
>
>

> Fred
>
> > --
> > Posted viahttp://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.



[Rails] How do I change the name of a label in a form?

2011-08-28 Thread Pepe Sanchez
Hi,

Instead of having on the labels the field name I would like to change it
some customized values.

How can I change that ?

Regards

%= form_for(@client_workout) do |f| %>


  
<%= f.label :client_name %>
<%= f.text_field :client_name %>
  
  
<%= f.label :trainer %>
<%= f.text_field :trainer %>
  
  
<%= f.label :duration_min %>
<%= f.text_field :duration_min %>
  
  
<%= f.label :date_of_workout %>
<%= f.date_select :date_of_workout %>
  
  
<%= f.label :paid_amount %>
<%= f.text_field :paid_amount %>
  
  
<%= f.submit %>
  
<% end %>

-- 
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.



[Rails] Error wit errrs

2011-08-28 Thread Neil Bye
I have an app which I have upgraded to rails3. It is working fine but
for displaying error messages.

Take i.e. new.html.erb. In the model I have several validations that
work, they do not create a user if the entries are wrong. On submission
it dutifully returns to new.html.erb but WITHOUT the nice red error
messages.

I have been using

  <% if @user.errors.any? %>

  <%= pluralize(@user.errors.count, "error") %> prohibited this
user from being saved:

  
  <% @user.errors.full_messages.each do |msg| %>
<%= msg %>
  <% end %>
  

  <% end %>

but that doesn't help. I think the problem may be deeper. Do you know
what files are used when displaying the errors? Where does the error
variable come from?. I have scaffold.css

Could it be a js problem? I am using jquery so do not have prototype or
scriptaculous. Could that be causing the problem?

-- 
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.



[Rails] Re: Full URLs in Rails logs

2011-08-28 Thread Frederick Cheung


On Aug 28, 9:39 am, J. Pablo Fernández  wrote:
> It is possible with monkey patching by creating an initializer like this:
>

I'm not entirely sure what you're trying to do, but there's nothing
stopping you creating your own log subscriber, attaching it to the
relevant events and log whatever you want

Fred
> class Rails::Rack::Logger < ActiveSupport::LogSubscriber
>   protected
>
>   def before_dispatch(env)
>     request = ActionDispatch::Request.new(env)
>     info "\n\nStarted #{request.request_method} \"#{request.url}\" for
> #{request.ip} at #{Time.now.to_default_s}"
>   end
> end
>
> Would there be any interest in having something like this, configurable, in
> Rails? (I did patches for Rails that never managed to gather enough
> popularity and were ignored, I'm not wasting my time again)

-- 
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.



[Rails] Re: Local timezone issues

2011-08-28 Thread Frederick Cheung


On Aug 28, 2:56 pm, comopasta Gr  wrote:
> Hi,
>
> So I store Visit records in UTC: 2011-08-28 13:23:48.714506
> I am in timezone +3 so I can verify that the stored created at is in
> UTC.
>
> Rails.logger.debug visits.last.created_at.class returns
> ActiveSupport::TimeWithZone
>
> I'm using pgAdmin3 and when checking the table on the UI app you can see
> the datatypes. Strangely there in the UI of pgAdmin3 it reads
> "created_at timestamp without time zone". That is odd.
>
> Based in what I've read the data is in DB in UTC but when it pulls it
> from the db it should convert it to local automatically.
>
> I am in zone +3 so I should get 16:23:48 for the record above. But it
> still comes in UTC.
>
> Any hints what could be the problem?
>

It converts the utc value from utc to whatever Time.zone is. Unless
you're setting Time.zone elsewhere, because you've set
config.time_zone to utc, Time.zone will be utc too. Try setting
config.time_zone to the desired timezone (don't forget to restart your
app)

Fred

> --
> Posted viahttp://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.



[Rails] Re: Class Variable

2011-08-28 Thread Frederick Cheung


On Aug 28, 3:14 pm, 7stud --  wrote:
> class Dog
>   @count = 0
>
>   def initialize
>     Dog.count += 1
>   end
>
>   def self.count
>     @count
>   end
>
>   def self.count=(val)
>     @count = val
>   end
>
> end

If you want to be entirely nit-picky those are class instance
variables rather than class variables.

Fred


>
> d1 = Dog.new
> puts Dog.count
>
> d2 = Dog.new
> puts Dog.count
>
> --output:--
> 1
> 2
>
> --
> Posted viahttp://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.



[Rails] Re: will_paginate generates undefined method paginate

2011-08-28 Thread Songhua H.
Without your answer, I would probably have witch-hunted forever... 
Thanks

hqmq wrote in post #731654:
> I found an easy solution to this problem...
> Stop the WEbrick server and start it again...
>
> Seems dumb I know, but I was using the method where you modify config/
> environment.rb to include this line:
>   config.gem 'mislav-will_paginate', :version => '~>
> 2.3.4', :lib => 'will_paginate', :source => 'http://gems.github.com' code>
> it should go right after the: Rails::Initializer.run do |config|
>  line
>
> then you perform sudo rake gems:install and it installs
> the gem for you.  But it was giving me this error message unti I
> stopped the WEbrick server and started it again.
>
> Go Figure...

-- 
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.



Re: [Rails] Re: Class Variable

2011-08-28 Thread Michael Pavling
On 28 August 2011 14:55, 7stud --  wrote:
> In addition, you shouldn't be using class variables.  You can forget
> they exist.

Bwah! Hahahah!

What tosh...

-- 
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.



[Rails] Re: image override*

2011-08-28 Thread comopasta Gr
> ...the image will override the some user...

Maybe its just me but I have a problem understanding what you mean with
that sentence. If you can't describe your problem clearly I doubt you'll
get an answer.

I have some apps where I take care of uploads myself but why aren't you
using some of the upload gems available? Like paperclip or carrierwave
for example? They do save work.

https://github.com/thoughtbot/paperclip
https://github.com/jnicklas/carrierwave

Cheers.

-- 
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.



Re: [Rails] Difference in passenger and rack

2011-08-28 Thread coolesting
Good explanation. Thanks Walter.

2011/8/27 Walter Lee Davis 

>
> On Aug 27, 2011, at 10:56 AM, coolesting wrote:
>
>  Hi, everyone,
>> I have googled it, but can't understood, i think they are as same as the
>> CGI in aspect of functional.
>> The passenger only for apache web server, the rack for every web server
>> that supports the rack, isn't it.
>> Thanks for the helps to solve my confusion.
>>
>
> Try this idea on.
>
> 1. Rack is a framework for building HTTP-aware applications in Ruby.
>
> 2. Rails is a Rack app, so is Sinatra.
>
> 3. Passenger is a module for Apache or Nginx that serves a Rack app
> alongside other HTTP assets.
>
> There are other ways to serve a Rack app, including CGI, FastCGI, Lighty,
> Thin, Unicorn, etc. Passenger is very easy to configure and use within an
> existing Apache server (the sort you're reasonably likely to see in a
> commodity hosting setup), and fairly fast, so it gets a lot of usage.
>
> Walter
>
> --
> 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+unsubscribe@**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.



[Rails] Re: Class Variable

2011-08-28 Thread 7stud --
class Dog
  @count = 0

  def initialize
Dog.count += 1
  end

  def self.count
@count
  end

  def self.count=(val)
@count = val
  end

end


d1 = Dog.new
puts Dog.count

d2 = Dog.new
puts Dog.count


--output:--
1
2

-- 
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.



[Rails] Re: iphone and android with RoR 3.x

2011-08-28 Thread comopasta Gr
Pepe Sanchez wrote in post #1018786:
> Hi all
>
> Any advice in how to build applications for smartphones with RoR ?
>
> Regards
> Jose

I you like ruby and RoR mechanics you can take a look at Rhodes. There 
you can use Ruby and MVC architecture just like you do in RoR to achieve 
multiplatform mobile support.

http://rhomobile.com/products/rhodes/

Cheers.

-- 
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.



[Rails] Local timezone issues

2011-08-28 Thread comopasta Gr
Hi,

I've checked many of the related timezone questions in the forum but
none helped.

I'm on Rails 3.0.6 and using Postgresql.

I have my server time zone set to UTC with config.time_zone = 'UTC' in
my application.rb (it should be default anyway)

So I store Visit records in UTC: 2011-08-28 13:23:48.714506
I am in timezone +3 so I can verify that the stored created at is in
UTC.

Rails.logger.debug visits.last.created_at.class returns
ActiveSupport::TimeWithZone

I'm using pgAdmin3 and when checking the table on the UI app you can see
the datatypes. Strangely there in the UI of pgAdmin3 it reads
"created_at timestamp without time zone". That is odd.

Based in what I've read the data is in DB in UTC but when it pulls it
from the db it should convert it to local automatically.

I am in zone +3 so I should get 16:23:48 for the record above. But it
still comes in UTC.

Any hints what could be the problem?

-- 
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.



[Rails] Re: Class Variable

2011-08-28 Thread 7stud --
thelo.g thelo wrote in post #101:
> Hi everyone,
>
> I have a question about class  variable in Rails:
>
> I have a class Point that contains an class variable
> @@color_points="green"
>
> In a first web Page I want to set up this variable, hence i do
> Point.color_points = "green" then i test it using puts
> Point.color_points ( = green, it works,yes!)
> Then i have a link_to instruction that points to another web page.
> On this one (the other one), I just want to print Point.color_points,
> but now its value is "".
>
> DOes anyone know why and could explain me?

In addition, you shouldn't be using class variables.  You can forget 
they exist.

-- 
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.



Re: [Rails] Full URLs in Rails logs

2011-08-28 Thread J . Pablo Fernández
Yes, I make re-usable code all the time... I released many gems and I have 
lot's of github repos. The part that was a waste of time was creating a 
patch for Rails.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/3t_3LDDADA0J.
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] Class Variable

2011-08-28 Thread Michael Pavling
On 28 August 2011 12:16, thelo.g thelo  wrote:
> In a first web Page I want to set up this variable
> then i test it using puts, it works,yes!
> Then i have a link_to instruction that points to another web page.
> but now its value is "".
>
> DOes anyone know why and could explain me?

Each request is isolated. At the end of the first request, all the
variables you've set disappear into the ether. If you want something
to persist, you need to store it - in the DB, the session, or
somewhere else.
The second request builds up new instances of all the objects - so the
class variable is back to its default value.

-- 
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.



[Rails] Class Variable

2011-08-28 Thread thelo.g thelo
Hi everyone,

I have a question about class  variable in Rails:

I have a class Point that contains an class variable
@@color_points="green"

In a first web Page I want to set up this variable, hence i do
Point.color_points = "green" then i test it using puts
Point.color_points ( = green, it works,yes!)
Then i have a link_to instruction that points to another web page.
On this one (the other one), I just want to print Point.color_points,
but now its value is "".

DOes anyone know why and could explain me?

-- 
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.



Re: [Rails] Full URLs in Rails logs

2011-08-28 Thread Jeremiah Dodds
2011/8/28 J. Pablo Fernández 
>
> Would there be any interest in having something like this, configurable, in
> Rails? (I did patches for Rails that never managed to gather enough
> popularity and were ignored, I'm not wasting my time again)
>

I wouldn't know, seems like it could be a somewhat common use case. I was
just tryin' to help ;)

In any case, I don't know about making it a patch, but you could make it
into a plugin and stick it on github and rubyforge. You'd be able to use it
from multiple apps easily, and if there *is* interest in it, people can use
it and contribute and whatnot.

Off-topic, making code like that reusable and public is never a waste of
time, imo. Every once in a while I'll get a thank-you or a feature request
for some little util I wrote, pushed public, and forgot -- and it's pretty
neat.

-- 
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.



[Rails] Re: Creating a related object before validation

2011-08-28 Thread J . Pablo Fernández
Thanks. My code looks more like yours now, using new instead of create. But 
save_person is not needed, in my case at least, the person gets saved 
automatically and as far as I know, all callbacks and the saving are wrapped 
in a transaction by Rails automatically.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/J_1znmqJZvgJ.
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.



[Rails] Re: Creating a related object before validation

2011-08-28 Thread J . Pablo Fernández
Thanks for pointing to after_initialize, your point 2 is very valid. About 
point 1, everything is wrapped automatically in a transaction by Rails and I 
have tests for it. Is that not the case (and my tests are passing due to the 
magic of the universe or something?).

My problem is a little bit more complex, as both users and people are in 
tenant, my code looks like this:

  def create_person
if person_id.nil? && person.nil?
  self.person = Person.new
  self.tenant.people << self.person
end
  end

The problem is that in after_initialize, self.tenant is still nil.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/x1QO3wjWSGcJ.
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.



[Rails] Re: Page Caching, CSRF, and Loading a form via Ajax

2011-08-28 Thread Frederick Cheung


On Aug 28, 5:48 am, Raviv M-G  wrote:
> Hi all,
>
> I would like to use page caching on my homepage, but also want to
> enable people to sign in via a modal dialog sign in form.  I could
> have a setup in which when a user lands on the cached homepage, an
> Ajax GET request pulls in the whole login form so that there is a
> fresh authenticity token.
>
> That said, besides the additional hit to the server, the CSRF token in
> the head area of the page could be different (left over in the page
> cache from another user).
>
> I'm guessing that loading a form like this through ajax is not
> advisable, but since it works and most people hit the site without
> signing in, I'm wondring why not just load the form via an ajax get
> call?
>
Well I'm sure that would work, but is there any point to CSRF
protection for a login form?

The aim of the token is to stop an attacker getting an already logged
in use to submit form data unwittingly, but with a login action it
doesn't seem like they can do any harm, since unless the attacker
knows the user's credentials all they are ever going to trigger is a
"bad login please try again" page. On top of that, when the CSRF token
doesn't match up, these days what happens is that your session gets
reset, so that the request gets handled like a non-logged user's
would.

Fred

> Thanks,
> Raviv

-- 
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] Creating a related object before validation

2011-08-28 Thread J . Pablo Fernández
As far as I know, all callbacks and the save is run inside a transaction, so 
if saving fails for the user, the person won't be save. I still had the 
issue that just calling user.valid? would create a record in the database 
when not expected. I did switch to calling new instead of create and all my 
tests about it are passing.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/_XagD0hIQ5UJ.
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.



[Rails] Re: Creating a related object before validation

2011-08-28 Thread Andrew DiMichele
I'm assuming you don't want to create a Person if your User
validations fail and vice versa. One way to do it is as follows. This
will validate your Person during the validation phase for User, and if
all is good save your Person then save User. Note that this doesn't
preclude any database constraint/error from screwing up your User
save, resulting in orphaned Persons. To be really safe you should wrap
both Person and User save operations in a transaction (http://
api.rubyonrails.org/classes/ActiveRecord/Transactions/
ClassMethods.html).

class User < ActiveRecord::Base
 bleongs_to :person, :validate => true

 before_validation :create_person
 before_create :save_person

 def create_person
if person.nil? && person_id.nil?
  self.person = Person.new(:name => email, :tenant => tenant)
end
  end

 def save_person
  self.person.save!
 end
end

On Aug 27, 12:42 pm, J. Pablo Fernández  wrote:
> Hello,
>
> I have two models, User and Person. Basically users are users of the system
> while people is a kind of address book. But every user is also a person so I
> created this relationship:
>
> class User < ActiveRecord::Base
>   belongs_to :person
> end
>
> class Person < ActiveRecord::Base
>   has_one :user
> end
>
> Now, on creating a user I want to automatically create a person. Is this the
> way to do it:
>
>   before_validation :create_person
>
>   def create_person
>     if person.nil? && person_id.nil?
>       self.person = Person.create!(:name => email, :tenant => tenant)
>     end
>   end
>
> Thanks.

-- 
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.



[Rails] Re: Creating a related object before validation

2011-08-28 Thread Jan Dudek
You might want to use after_initialize callback, e.g.

  after_initialize :build_person_if_no_person

  def build_person_if_no_person
build_person if new_record? && person.nil?
  end

The person.nil? check might be needed in some cases, for example if
you want to use Person.new.build_user.

(I did not try the above code, but this is almost an excerpt from my
application, which uses this approach).

I wouldn't recommend creating object in before_validation callback,
because:
1) when validation fails, you're left with not needed Person records
in the database
2) one day you may want to save User and skip validation, in which
case you won't have the Person object created.

Overall, I like the idea of using composition between User and Person
instead of inheritance - I usually do it the same way in my
applications.

-- 
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.



[Rails] Page Caching, CSRF, and Loading a form via Ajax

2011-08-28 Thread Raviv M-G
Hi all,

I would like to use page caching on my homepage, but also want to
enable people to sign in via a modal dialog sign in form.  I could
have a setup in which when a user lands on the cached homepage, an
Ajax GET request pulls in the whole login form so that there is a
fresh authenticity token.

That said, besides the additional hit to the server, the CSRF token in
the head area of the page could be different (left over in the page
cache from another user).

I'm guessing that loading a form like this through ajax is not
advisable, but since it works and most people hit the site without
signing in, I'm wondring why not just load the form via an ajax get
call?

Thanks,
Raviv

-- 
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.



[Rails] Re: iphone and android with RoR 3.x

2011-08-28 Thread John Moses
Look into using Sencha Touch and Phonegap...
http://www.sencha.com/learn/a-sencha-touch-mvc-application-with-phonegap

On Aug 27, 7:06 am, Pepe Sanchez  wrote:
> Hi all
>
> Any advice in how to build applications for smartphones with RoR ?
>
> Regards
> Jose
>
> --
> Posted viahttp://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.



[Rails] Re: Active Record Question

2011-08-28 Thread John Doe
Also, in my controller, I'd like to call the parent controller's
method to format my json in a certain way...So instead of this:

respond_to do |format|
  format.json { render :json => @projects.to_json(:include =>
[:apps]) }
end

I'd like to do something like this:

result = 
respond_to do |format|
  format.json { render :json =>
some_method_in_parent_controller(result) }
end

So all my other controllers that subclass this parent application
controller can pass data to this parent controller's method and format
the data in a particular way.

How do I achieve this? Please help! Thanks!

On Aug 27, 7:47 am, Frederick Cheung 
wrote:
> On Aug 27, 8:35 am, John Doe  wrote:
>
>
>
> > In my projects controller, I am trying to do this:
>
> > @projects = Project.find(:all, :include => [:books])
>
> > My hope is to get a nested data structure back that looks something
> > like:
>
> Well you what you get back is an array of projects where the book
> objects have already been fetched fro the database
> If you call to_json(:include => :books) then you should get output
> pretty similar to what you've described.
>
> Fred
>
>
>
>
>
>
>
> > projects: [
> >   {
> >     ..,
> >     books: [
> >         {
> >           ..
> >         },
> >         {
> >           ..
> >         }
> >     ]
> >   }
> > ]
>
> > But that does't work. How can I achieve this?
>
> > Thanks in advance!

-- 
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] Full URLs in Rails logs

2011-08-28 Thread J . Pablo Fernández
It is possible with monkey patching by creating an initializer like this:

class Rails::Rack::Logger < ActiveSupport::LogSubscriber
  protected

  def before_dispatch(env)
request = ActionDispatch::Request.new(env)
info "\n\nStarted #{request.request_method} \"#{request.url}\" for 
#{request.ip} at #{Time.now.to_default_s}"
  end
end

Would there be any interest in having something like this, configurable, in 
Rails? (I did patches for Rails that never managed to gather enough 
popularity and were ignored, I'm not wasting my time again)

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/azy80IMf8-cJ.
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.