Ruby on Rails Sunday, September 5, 2010

2010/9/4 Pål Bergström <lists@ruby-forum.com>:
> I'm trying to pass a value from a cookie from the controller into model
> by using attr_accessor. But it doesn't work and I suspect I do something
> wrong.
>
> Is this on the right path?
>
> class Test < ActiveRecord::Base
>
>  attr_accessor :key
>
>  .... key ..
>
> end
>
> class TestController < ApplicationController
>  def new
>    @test = Test.new
>    @test.key = cookies[:my_key]

You could alternatively say
@my_key = cookies[:my_key]
then access @my_key in the view. If the key is logically an attribute
of Test then use your method, if you are just putting it there in
order to pass it to the view then it may be more logical to use a
separate variable.

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

No comments:

Post a Comment