7stud -- | 1 Aug 01:11 2011

Re: Question about Helpers

Filippos wrote in post #1014053:
> wow thanx!
>
>
>
>>   puts "woof"
>>    'not known'
>>   end
>>  end
>>
>>  def show
>>   puts  <at> color
>>   puts self.color *
>>  end
>> end
>
> * so in this context self.color calls the color method of the Dog
> class for the d object (d.color) . What if we omitted "self" , would
> rails execute the color method with the same result?
>

Yes, when a method is called without "a receiver", i.e without an object 
in front of it, then ruby calls the method with self.  In fact, all 
methods have to have a receiver, i.e an object that calls the method, so 
if you don't provide one, ruby uses self.  One time when you do have to 
explicitly write self is when you are on the left side of an equals 
sign:

color = "black"

(Continue reading)

7stud -- | 1 Aug 01:47 2011

Re: Question about Helpers

Uggh.  There must be a hole in my tests:

  def get_user_from_cookie
     <at> current_user || begin
      cookie_array = cookies.signed[:remember_token]

      if cookie_array
         <at> current_user = User.authenticate_with_salt(*cookie_arr)
        return  <at> current_user
      else
        return nil
      end

    end # || block
  end

*cookie_arr should be *cookie_array.  But my tests didn't throw an 
error.

-- 
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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Andrew Skegg | 1 Aug 03:08 2011

Re: Character encode

Alcelyo Roberto <alcelyo <at> ...> writes:

> 
> 
> Good evening guys,I'm using now with 3 rails web app themes rails to 
generate the layouts, almosteverything working ok, only the names I 
write code in such a ride when I put atable in the 
header with character "ç" character shows the strange but data thatcomes from 
the database shows normal, which can be and how can I fix? Thank you all ...-- 
Alcelyo R MarizBacharel em Sistemas de Informação
> 

It is probably being escaped for browser safety.  If you can trust the data, 
try using "raw":

<= raw  <at> variable.stuff >

--

-- 
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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Filippos | 1 Aug 03:38 2011
Picon

Re: Question about Helpers

your implementation makes more sense to me than the example of the
book.

In your code you write:

def get_user_from_cookie
 <at> current_user || begin   <------- what is the begin ? or is that line
code a typo?

Pffff... it took me back to basics!
According to the book with attr_accessor we create virtual attributes
(when we dont want to save something in the database).
But it uses them inside a model class (user class) so it's been called
as self.password (when attr_accessor :password)
I didn't see it outside a model class so im having problems
understanding and getting used to getter and setter outside a model
class since its the same thing.
Not to mention the "self" outside a model class... very strange.

So the logic behind Helpers and the module  is that when we're not
using a model (px for Sessions) and since the code needed for sign-
in / sign-out doesn't involve an action-view relationship like with
Controllers -it's just methods and programming-
we use the SessionsHelper with modules and not the
ApplicationController.

About the methods.

def method1
...
(Continue reading)

Jim Ruther Nill | 1 Aug 06:05 2011
Picon

Re: Importing LinkedIn Contacts



On Sun, Jul 31, 2011 at 11:00 PM, Srikanth Jeeva <lists <at> ruby-forum.com> wrote:
Hi,

After an user signs up in my website, I have to

1. Give him a linkedin button, clicking it the user will be redirected
to linkedin website for authentication.
2. once Authenticated and user returns back to my webpage, I need to
import the user's contacts from Linkedin.
3. Display the users's linkedin contacts in a page.
4. User selects some contacts and clicking submit, will send a invite
message to those selected contacts.

Is there any Gem or plugin in rails 3 to achieve this?


i'm also about to integrate an app with linkedin. googling 'linkedin api gem ruby' gave
me https://github.com/pengwynn/linkedin. so you might want to check that out :)
 
Regards,
Srikanth Jeeva

--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.




--
-------------------------------------------------------------
visit my blog at http://jimlabs.heroku.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Rafael Fernández López | 1 Aug 02:13 2011
Picon

Limit number of requests per second

Hi all,

I have searched for the solution of this problem and found none, for
this reason I am writing here.

Basically, what I intend to do is pretty easy, and can be achieved with
several typical solutions easily. However I want to know if there is a
'rails way' to do this. Particularly, a 'rails 3 way', since I went with
Rails 3 for this project.

I have a typical Rails application, in which the special thing is that I
am accessing through SSH to some selected Cisco routers (in order to
read some infos from it). Since it is a public applicacion, it could be
that too many requests come at the same time and the application can
literally 'crash' the router because of too many work.

I want to know if there is some recommended way of setting a limit on
how many people can concurrently request something to the controller.

In order to run the application in production mode I will do it with
Passenger + Apache/nginx.

Best regards, and thanks in advance,
Rafael Fernández López.

--

-- 
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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Chknout | 1 Aug 04:45 2011
Picon

algorithm for finding a list of matches

Hi

I am looking for an algorithm that matches a job applicant with a list
of potential job openings

is there an algorithm (like a graph?) that does this efficiently?

is there a Gem that does this?

thx

--

-- 
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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Chris Kottom | 1 Aug 08:22 2011

Re: Re: setting an extra attribute of the join model.

I think your problem is in the way you've used the AR relationships in constructing the form you have there.  Your form is using the has-many-through relationship from Delivery to Product to construct the form.  This was all right before you had anything meaningful at the DeliveryItem level, but now the whole form needs to be reworked to stop thinking of Delivery as a bunch of Products and instead as a number of DeliveryItems, each of which is associated with a Product.

I haven't had to do anything like this before, but I would try to solve it as follows:
  1. Add an accepts_nested_attributes_for call to Delivery for :delivery_items.
  2. Add a quantity attribute to DeliveryItem 
  3. Change the form from a single select with a list of Products to a number of rows, each with a single-item select for Product and a text field for entering quantity.

On Mon, Aug 1, 2011 at 12:50 AM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
On 31 July 2011 22:52, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> On Sun, Jul 31, 2011 at 1:47 PM, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>>
>> On Sun, Jul 31, 2011 at 11:12 AM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>>>
>>> On 30 July 2011 21:22, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>>> > https://gist.github.com/1114858.
>>> > How can I set the quantity DeliveryItem in the same form so that when
>>> > I update the customer attributes the Delivery is created with products
>>> > and their quantity?
>>> >
>>>
>>> no solution?
>>>
>>
>> Mauro, I'm not 100% sure what you're trying to ask here.  Thus, could you
>> explain
>> the steps starting with how the user would interact with the form to
>> what you would
>> like to happen?  For example,
>> a)  The user navigates to the page containing the form.
>> b)  The user does X
>> c)  ...

Ok, sorry but my english is really bad..........
Then, as you see in the code the Customer has many deliveries and one
Delivery has many products through delivery_items.
I want to do this: I call the show action for Customer;
I view customer details and a form to create a delivery for that customer.
The delivery has one or more products.
When I submit the form it creates the delivery for the customer with
one or more delivery_items, that is the join model.
The delivery_item contains the product but the quantity attribute is
nil, I want to populate the quantity when the delivery was created so
that the delivery has products with their quantity.
>
> Or do you have tests which might add some clarity to what you're trying to
> achieve?
>
>>
>> -Conrad
>>
>>>
>>> --
>>> 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
>>> To unsubscribe from this group, send email to
>>> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
>>> 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
> 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe <at> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
7stud -- | 1 Aug 10:08 2011

Re: Question about Helpers

Filippos wrote in post #1014091:
> your implementation makes more sense to me than the example of the
> book.
>
> In your code you write:
>
> def get_user_from_cookie
>  <at> current_user || begin   <------- what is the begin ? or is that line
> code a typo?
>

The begin-end block allows you to write multiple lines of code on the 
right side of an ||.  It's the same as if you did this:

 <at> current_user  || method_1

def method 1
      cookie_array = cookies.signed[:remember_token]

      if cookie_array
         <at> current_user = User.authenticate_with_salt(*cookie_arr)
        return  <at> current_user
      else
        return nil
      end
end

The return value of method1 gets inserted in place of the method1 
'function' call on the right side of the ||.

> Pffff... it took me back to basics!
> According to the book with attr_accessor we create virtual attributes
> (when we dont want to save something in the database).
> But it uses them inside a model class (user class) so it's been called
> as self.password (when attr_accessor :password)
> I didn't see it outside a model class so im having problems
> understanding and getting used to getter and setter outside a model
> class since its the same thing.

All classes have the same abilities in ruby.  It doesn't matter whether 
you call a class a Model or a Controller or something else.

>
> Not to mention the "self" outside a model class... very strange.
>

self refers to different objects depending on where you are in your 
code.  The two main places that you need to know about is:

1) Inside a class but outside any def's, self refers to the class.
2) Inside a method definition, self refers to the object calling the 
method.  And it appears that in most situations in rails, that is going 
to be the sess_controller = SessionsController.new object.  Of course if 
you are inside a method in the UsersController, then rails will call 
those actions using a users_contr = UsersController.new object.

> So the logic behind Helpers and the module  is that when we're not
> using a model (px for Sessions) and since the code needed for sign-
> in / sign-out doesn't involve an action-view relationship like with
> Controllers -it's just methods and programming-
>
Apparently, rails allows you to put some methods into a common directory 
when you want to use them in more than one controller.   You put the 
methods inside a module, and save the file in the app/helpers directory. 
Then if you want to use the methods in a certain controller you write 
'include ModuleName' in the application_controller.rb file:

class ApplicationController < ActionController::Base
  protect_from_forgery
  include SessionsHelper
end

and that inserts the bundle of methods in the ApplicationController 
class. And because your controllers all inherit from the 
ApplicationController class:

class SessionsController < ApplicationController

...you can call any of the methods in the bundle from inside the actions 
in the SessionsController class.

>
> About the methods.
>
> def method1
> ...
> end
>
> is one type of method which doesn't require an argument
> whereas
>
> def method2(string1, string2, string3...)
> ...
> end
>
> is the other type which requires input.
>

Yes.

> So you mean that since we dont write "self" Rails infers:
>
> self.method1 and self.method2(string1, string2, string3...) when we
> call them?
>

Yes.  All methods must be called by some object.   If you don't 
explicitly write the object in front of the method call, then ruby uses 
self.

> with self being the session_controller = SessionsController.new  or
> session_helper = SessionsHelper.new?
>

Inside an action, self will be the object calling the action, which will 
be the controller instance that rails creates to call the action.  So 
for a SessionsController action, rails will create a sess_controller = 
SessionsController.new object, and for a UsersController rails will 
create a users_contr = UsersController.new object.  The only way you can 
call methods in a class is if you first create an object of the class, 
and then use that object to call the methods.  A controller is just a 
ruby class, and actions are just methods inside a class, so in order for 
an action to execute, it has to be called using an object of that class.

The reason the tests did not catch the typo in my code is because in the 
tests, is because the create actions calls the signed_in helper method, 
and signed_in does this:

 <at> current_user = user

So when get_user_from_cookie is called:

def get_user_from_cookie
     <at> current_user || begin ....
     ....

 <at> current_user is always true, so the right side of the || never 
executes.  In other words, the tests we have written so far do not test 
the case when  <at> current_user = nil.  I don't know if that is an 
oversight, or whether that will be tested later.

-- 
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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Mauro | 1 Aug 10:41 2011
Picon

Re: Re: setting an extra attribute of the join model.

On 1 August 2011 08:22, Chris Kottom <chris@...> wrote:

> Add an accepts_nested_attributes_for call to Delivery for :delivery_items.

done

> Add a quantity attribute to DeliveryItem

already done

> Change the form from a single select with a list of Products to a number of
> rows, each with a single-item select for Product and a text field for
> entering quantity.

But DeliveryItem belongs_to :product so to add, say three products, I
have to create three delivery_items submitting the form three times.

--

-- 
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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.


Gmane