[Rails] List all field names on a PDF using iText from Rails

2009-05-24 Thread Dan Sadaka

Hello everyone,

Has anyone used iText to list all fields on a PDF AcroForm?
There are plenty of java examples to do it, but I do not know how to
translate that into ruby.  I'm using Rjb.

The Java example I've found is:

AcroFields form = reader.getAcroFields();
HashMap fields = form.getFields();
String key;
for (Iterator i = fields.keySet().iterator(); i.hasNext(); ) {
  key = (String) i.next();
  System.out.print(key + ": ");
  switch(form.getFieldType(key)) {
case AcroFields.FIELD_TYPE_CHECKBOX:
  System.out.println("Checkbox");
  break;
case... (other types)
  }
}

TIA,
Dan
-- 
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] form_for v/s field_for

2009-05-24 Thread Virendra Negi

Hello
I am trying to use complex-form in my application for which i have to
use field_for i want to know exactly the main difference of form_for and
field_for

and the logic behind field_for

thanks anyway
-- 
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: bug adapter firebird 2.1.2 ?

2009-05-24 Thread Mariarosaria Trovato

Confermato:
Data: 23/05/2009 11:33
Mittente: Brent Rowland

I can confirm there is a bug interpreting the results of aggregate
operators such as SUM and AVG. I suggest performing these operations
in code, rather than in the database, until a fix can be made.

Brent
http://rubyforge.org/tracker/index.php?func=detail&aid=25938&group_id=1774&atid=6946
-- 
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: onChange => remote_function - Not able to get current id

2009-05-24 Thread Julian Leviston

On 25/05/2009, at 3:16 PM, Devi Rv wrote:

>
> Hi,
>
> Below is the code I am using to display drop down. This drop down is  
> for
> displaying categories.
>
> <% form_for :category do |form| %>
>  <%= form.collection_select(:id,@categories, :id,
>:category_name, {},
>{:onChange => remote_function(:url=>{:action=>'say_hello',
>:with => "'id='+value"},
>:update=>'mydiv')}
>   )  %>
> <% end %>
>
> I want to get the 'current category id' during onchange. Using :with  
> =>
> "'id='+value" I am not able to get it.
>
>


For a start, you have :with as part of the :url hash... it should be  
on the same level as :update.

Julian.

--
Blog: http://random8.zenunit.com/
Twitter: http://twitter.com/random8r
Learn: http://sensei.zenunit.com/
Latest: How to use Unix basics at http://sensei.zenunit.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: after_create and has_one association bug?

2009-05-24 Thread Julian Leviston


On 25/05/2009, at 3:46 PM, Andrew Kaspick wrote:

>
> Hello,
>
> I've come across an issue that I'm sure is a bug when using  
> after_create
> with a has_one association, but I'm not 100% certain if I'm missing
> something.
>

Perhaps you should file a bug?

http://rails.lighthouseapp.com

--
Blog: http://random8.zenunit.com/
Twitter: http://twitter.com/random8r
Learn: http://sensei.zenunit.com/
Latest: How to use Unix basics at http://sensei.zenunit.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: onChange => remote_function - Not able to get current id

2009-05-24 Thread Bob

Maybe "with" section should look like with => 'id='+value? I think in
your variant you assign to id a string value 'value'.

Regards,
Bob

On 25 май, 09:16, Devi Rv  wrote:
> Hi,
>
> Below is the code I am using to display drop down. This drop down is for
> displaying categories.
>
> <% form_for :category do |form| %>
>   <%= form.collection_select(:id,@categories, :id,
>     :category_name, {},
>     {:onChange => remote_function(:url=>{:action=>'say_hello',
>         :with => "'id='+value"},
>         :update=>'mydiv')}
>        )  %>
> <% end %>
>
> I want to get the 'current category id' during onchange. Using :with =>
> "'id='+value" I am not able to get it.
>
> Plaese anyone suggest
> --
> 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: after_create and has_one association bug?

2009-05-24 Thread Andrew Kaspick

Oh, forgot to mention... rails 2.3.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] after_create and has_one association bug?

2009-05-24 Thread Andrew Kaspick

Hello,

I've come across an issue that I'm sure is a bug when using after_create
with a has_one association, but I'm not 100% certain if I'm missing
something.

This is pretty much exactly the code I'm using.  Two simple classes
(Account and Contact) and I create the contact after I create an account
(via after_create).  I'm not passing in a "name" field which the contact
requires via validates_presence_of, so the contact should not get saved,
but it in fact does.

class Account < ActiveRecord::Base
  has_one :contact
  def after_create
create_contact
  end
end

class Contact < ActiveRecord::Base
  belongs_to :account
  validates_presence_of :name
end

The test...

class AccountTest < ActiveSupport::TestCase
  test "this ain't right" do
a = Account.create
p a.contact
p a.new_record?
  end
end

produces...

#
false

Is this expected behaviour?

Thanks,
Andrew
-- 
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 running migration

2009-05-24 Thread Rick

This says it all: Unknown database '[my_database_name]_development'

Before you can migrate your new table you need to create the
database.  Evidently you are set up to use mysql.  If you check the
file config/database.yml you will see something like:

development:
  adapter: mysql
  encoding: utf8
  reconnect: false
  database: testmysql_development
  pool: 5
  username: root
  password:
  socket: /tmp/mysql.sock

where "testmysql" will be the name of your project
("my_database_name"?).  You will need to create a database with
"YOUR_PROJECT_NAME_development" that can be accessed by the user
identified by "username:" and "password:".  Then you can run rake
db:migrate.


On May 24, 7:16 pm, Virendra Negi 
wrote:
> Hello
>  I generate a scaffold for the User it created a migration for me for
> user table
>  now when iam trying to run that migration its give me a error
>  a ran the migration command with --trace to crack down the source of
> the error
>  but it should me this bunch of things and its not getting to my head
>
> ** Invoke db:migrate (first_time)
> ** Invoke environment (first_time)
> ** Execute environment
> ** Execute db:migrate
> rake aborted!
> Unknown database '[my_database_name]_development'
>
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/mysql_adapter.rb:576:in
> `real_connect'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/mysql_adapter.rb:576:in
> `connect'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/mysql_adapter.rb:204:in
> `initialize'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/mysql_adapter.rb:76:in
> `new'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/mysql_adapter.rb:76:in
> `mysql_connection'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in
> `send'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in
> `new_connection'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:245:in
> `checkout_new_connection'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:188:in
> `checkout'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:184:in
> `loop'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:184:in
> `checkout'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/1.8/monitor.rb:238:in `synchronize'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:183:in
> `checkout'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:98:in
> `connection'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:326:in
> `retrieve_connection'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:123:in
> `retrieve_connection'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:115:in
> `connection'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/migration.rb:435:in
> `initialize'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/migration.rb:400:in
> `new'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/migration.rb:400:in
> `up'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/migration.rb:383:in
> `migrate'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/tasks/databases.rake:116
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:617:in
> `call'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:617:in
> `execute'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:612:in
> `each'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:612:in
> `execute'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:578:in
> `invoke_with_call_chain'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/1.8/monitor.rb:238:in `synchronize'
> /PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:571:in
> `invoke_with_call_chain'
> /PROGRA~1/BITNAM~1/ruby/lib/

[Rails] Error running migration

2009-05-24 Thread Virendra Negi

Hello
 I generate a scaffold for the User it created a migration for me for
user table
 now when iam trying to run that migration its give me a error
 a ran the migration command with --trace to crack down the source of
the error
 but it should me this bunch of things and its not getting to my head


** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
Unknown database '[my_database_name]_development'

/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/mysql_adapter.rb:576:in
`real_connect'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/mysql_adapter.rb:576:in
`connect'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/mysql_adapter.rb:204:in
`initialize'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/mysql_adapter.rb:76:in
`new'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/mysql_adapter.rb:76:in
`mysql_connection'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in
`send'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in
`new_connection'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:245:in
`checkout_new_connection'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:188:in
`checkout'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:184:in
`loop'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:184:in
`checkout'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/1.8/monitor.rb:238:in `synchronize'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:183:in
`checkout'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:98:in
`connection'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:326:in
`retrieve_connection'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:123:in
`retrieve_connection'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:115:in
`connection'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/migration.rb:435:in
`initialize'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/migration.rb:400:in
`new'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/migration.rb:400:in
`up'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/migration.rb:383:in
`migrate'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/tasks/databases.rake:116
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:617:in
`call'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:617:in
`execute'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:612:in
`each'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:612:in
`execute'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:578:in
`invoke_with_call_chain'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/1.8/monitor.rb:238:in `synchronize'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:571:in
`invoke_with_call_chain'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:564:in
`invoke'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2027:in
`invoke_task'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in
`top_level'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in
`each'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in
`top_level'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2044:in
`standard_exception_handling'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1999:in
`top_level'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1977:in
`run'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2044:in
`standard_exception_handling'
/PROGRA~1/BITNAM~1/ruby/lib/ruby/gems/1.8/gems/rake-0.8

[Rails] onChange => remote_function - Not able to get current id

2009-05-24 Thread Devi Rv

Hi,

Below is the code I am using to display drop down. This drop down is for
displaying categories.

<% form_for :category do |form| %>
  <%= form.collection_select(:id,@categories, :id,
:category_name, {},
{:onChange => remote_function(:url=>{:action=>'say_hello',
:with => "'id='+value"},
:update=>'mydiv')}
   )  %>
<% end %>

I want to get the 'current category id' during onchange. Using :with =>
"'id='+value" I am not able to get it.


Plaese anyone suggest
-- 
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: update page with results as they are scraped

2009-05-24 Thread Sudhi Kulkarni

Jack Bauer wrote:
> I do something similar in one of my apps. The way I handle it is using 
> periodically_call_remote every 6 seconds and check it against a 
> controller action which looks at the DB to see if any new records were 
> added for that user since the last time it checked. If there are, do a 
> render :update |page| and add an insert_html with the new record on top.
> 
> Naturally you can increase or decrease the time between checks, but I 
> figure 5-10 seconds should be good for anyone.
> 
> For my specific app, if I was scraping 5 items specifically, the 
> periodically_call_remote function would turn itself off after I returned 
> 5 records.

Hi Jack,

How do you turn off a periodically_call_remote? Also is it possible to 
call periodically_call_remote on some action?

Thanks,
Sudhindra
-- 
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] a way that helper functions not produce XHTML but HTML?

2009-05-24 Thread SpringFlowers AutumnMoon



I would like to use HTML 4.01 Strict, and used a DOCTYPE of it in my
application template. But look like when a style sheet is included by a
helper function

  <%= stylesheet_link_tag 'style' %>

the code produced is XHTML:

  

is there a way to ask Rails to use HTML instead of XHTML?
-- 
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] periodic update related question

2009-05-24 Thread Sudhi Kulkarni

HI,

I am looking to do something like the following -- "Update a text area
with the content of a file on the server every 5 second once. This
activity should start once the "Run" button on my page is clicked"

What is the best approach to do this? The file is a log file so no
security concerns.

Thanks,
Sudhindra
-- 
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: belongs_to not saving foreign key

2009-05-24 Thread Erdwin Lianata

before the update_attributes line, try adding

b = Book.find(:first, "title => 'rails'")

then

b.update_attributes! :author_id => a2.id


It seems that update_attributes will work from found object, not newly 
created object, and this is normally done under update action of controller



Sean K wrote:
> Under Rails 2.3.2 using a completely brand new project, I have 2
> models:
> 
> class Author < ActiveRecord::Base
>   # name:string
> end
> 
> class Book < ActiveRecord::Base
>   # title:string
>   belongs_to :author # author_id
> end
> 
> And a simple test where i create a Book with an Author using the
> belongs_to and then update the foreign key directly:
> 
> require 'test_helper'
> 
> class BookTest < ActiveSupport::TestCase
>   test "foreign key updating" do
> a1 = Author.create! :name => 'author 1'
> b = Book.create! :title => 'rails', :author => a1
> a2 = Author.create! :name => 'author 2'
> b.update_attributes! :author_id => a2.id
> assert_equal a2.id, b.author_id  # author_id is still a1.id!
>   end
> end
> 
> The test fails on the last line.   Am i doing something wrong or is
> this expected behaviour?

--~--~-~--~~~---~--~~
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] Vote for Ruby on App Engine

2009-05-24 Thread tashfeen.ekram

On the feature list for next languages to be supported by the App
engine, ruby is losing to php. please go vote for ruby...

http://code.google.com/p/googleappengine/issues/list?q=rails&updated=29&ts=1243221608

just "star" it and who knows we might win the race...
--~--~-~--~~~---~--~~
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: sql Rand() returns same result

2009-05-24 Thread E. Litwin

My bad - I didn't notice the quotes around "rand()" in the first
post.

I thought a random number was being passed to the database rather than
a function.

On May 24, 8:10 am, Hassan Schroeder 
wrote:
> On Sat, May 23, 2009 at 10:06 PM, E. Litwin  wrote:
>
> Speaking strictly from a MySQL perspective --
>
> > First of all, I'm assuming you are calling rand() (lowercase).
>
> Case isn't significant.
>
> > I don't really understand what you are trying to randomize in your
> > order parameter.
> > You should probably get the count of the records in your table and
> > generate a random number between 1 and that count. Then use offset to
>
> ? The syntax below works just fine to return a random instance of
> Model.
>
> >> I have a method that calls Model.find(:first, :order => "RAND()")
> >> twice. I want it to return two different results but it always returns
> >> the same thing twice.
>
> What it *doesn't* do is guarantee that any two randomly selected
> instances won't be the same :-)
>
> Quick example:>> (1..20).each do
>
> ?> @up = UserProfile.find(:first, :order => "rand()")>> puts @up.id
> >> end
>
> 8
> 8
> 11
> 1
> 5
> 1
> 13
> 13
> 2
> 6
> 17
> 5
> 4
> 9
> 6
> 17
> 8
> 10
> 7
> 5
> => 1..20
>
> If the two really need to be different, you'll have to address that with
> application logic.
>
> FWIW,
> --
> Hassan Schroeder  hassan.schroe...@gmail.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] how upload file

2009-05-24 Thread pleb...@gmail.com

Hello,
i wonder about upload file in rails because i want user can browse the
file .
what fuction that i use? and please explain about upload file to me
because i never do it.
thank you
--~--~-~--~~~---~--~~
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: Passing a JavaScript variable through a Rails params hash

2009-05-24 Thread Julian Leviston

Hi

You need to change the target attrubute of the form tag. Give it an id  
if it doesn't have one:
form_tag({:action =>"update"}, {:id => "the_form"}) do
...
Then if using prototype, $('the_form').target += '&varname='+var;

Mind you URL encode the params value. You can use the escapeHTML  
string class to encode it properly if using prototype. I think there  
is also an escape function ;)

Blog: http://random8.zenunit.com/
Twitter: http://twitter.com/random8r
Learn: http://sensei.zenunit.com/
New video up now at http://sensei.zenunit.com/ real fastcgi rails  
deploy process! Check it out now!


On 25/05/2009, at 10:40 AM, Jon Hope  wrote:

>
> Hi guys, hoping someone can give me a pointer with this?
>
> I have a Javascript variable that I'm updating dynamically as a user
> interacts with the page. I want the user to be able to save it's value
> at any time along with some text data in a pop-up form, so the best  
> way
> I can think of is to pass it through the params hash without writing  
> it
> into the form. I'm not totally sure how to do this though?
>
> The only practical solution i've got is for a hidden field line in the
> form to be dynamically generated when the user goes to save it, but  
> this
> feels like overkill to me. Does anyone have any suggestions for a  
> neater
> way to do it?
>
> Thanks,
>
> Jon
> -- 
> 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] Rails page caching with separately cached global elements.

2009-05-24 Thread Steven Hilton

I'm trying to build an optimized caching setup for my app.

Large parts of the app will use full page caching (using something
like Ben Scofield's  Progressive Enhancement approach
http://www.slideshare.net/bscofield/page-caching-resurrected.)

The issue is: I'd like to include some global elements on all pages,
where the global element changes much more rapidly that most other
pages on the site, and I don't want to expire nearly all the pages on
the site because a minor global element needs to be updated.

An example of this is "10 most recent blog posts." shown on every
page. The RailsEnvy tutorial on caching
(http://www.railsenvy.com/2007/2/28/rails-caching-tutorial  ) uses
this example as a case where you _would_ need to clear the whole
cache, so maybe I'm being a little too creative here.

I was hoping to do this with SSI as apache serves the cached pages, as in:


This doesn't work because:
1: On the rails side, if page caching is turned off, the include is
ignored and the element is empty when the page is rendered
dynamically.

2: If the page is cached, but the element included via ssi doesn't
exist on the file system, it results in a routing error.

Google says some people have tried this, but I haven't seen a howto or
successful report of this approach. After fumbling around and
searching for a couple hours, I get the sense that this is trickier
than it sounds:
* Knowing when the SSI include statement should be processed by rails
or by apache2
* Getting apache to ssi include a file that doesn't exist and needs to
be generated on the fly
* Getting rails to include the ssi content served to the client, by
not including the ssi for the content cached to the file system

So, I'm looking for alternative approaches or more input on this
approach. Is something like this even possible now? One thing that may make
this work is if I can get the ssi to only conditionally include the
file if the file exists.

Something like this:

  

  
 Non-dynamic text to go here.
  

But SSI doesn't seem to support file tests or some similar workaround
that I've found

I *could* (and may) use a javascript layering approach on the client side,
but then the content in the global elements would not be visible to
spiders used to build search indexes, which is not really desirable.

Thanks for any feedback.


-- 
Steven Hilton 

--~--~-~--~~~---~--~~
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: Mongrel error on read file after upload

2009-05-24 Thread Jim ruther Nill

Frederick Cheung wrote:
> On May 22, 10:32�am, Jim ruther Nill  s.net> wrote:
> 
> Does the java code run as a different user than your mongrel ?
> 
> Fred

i'll try asking that to the java developers. I have no control over the 
java code. i'll keep you posted. 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] Passing a JavaScript variable through a Rails params hash

2009-05-24 Thread Jon Hope

Hi guys, hoping someone can give me a pointer with this?

I have a Javascript variable that I'm updating dynamically as a user
interacts with the page. I want the user to be able to save it's value
at any time along with some text data in a pop-up form, so the best way
I can think of is to pass it through the params hash without writing it
into the form. I'm not totally sure how to do this though?

The only practical solution i've got is for a hidden field line in the
form to be dynamically generated when the user goes to save it, but this
feels like overkill to me. Does anyone have any suggestions for a neater
way to do it?

Thanks,

Jon
-- 
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: is f.submit in a form_for newer than submit_tag?

2009-05-24 Thread Franco Catena

All the method in the form helper have his "object implicit"
counterpart, for example you can call text_field(object_name, method,
options = {}) or f.text_field(method, options = {}) and the object
used is f.object (the parameter of form_for @something), they produce
exactly the same output.

Regards.

Franco Catena.

On May 24, 6:06 pm, SpringFlowers AutumnMoon  wrote:
> some books or even the rails api uses
>
> form_for ...
>   ...
>   submit_tag ...
> end
>
> and i found that the Rails 2.3.2 Scaffold uses
>
> f.submit "Go"
>
> instead...  and this is not in the rails api doc.  Is this a new
> addition and is it suppose to replace submit_tag?
> --
> 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: Rails 2.3 memcache performance drop

2009-05-24 Thread Conrad Taylor
On Sun, May 24, 2009 at 10:07 AM, erik  wrote:

>
> Hi-
>  Could tell me how you replaced it?  I just installed the newest gem
> 1.7.2 and would like to use it with rails.  What's the procedure to
> remove the bundled gem?
> Thanks.
> Erik
>
> On Apr 8, 8:14 pm, Ryan Allen  wrote:
> > It turned out that the bundled memcache client that came with
> > ActiveSupport (1.6.5) was, for some reason, _much_ slower than the one
> > we were using before the Rails 2.3 upgrade (we were using fiveruns-
> > memcache-client (1.5.0.5), the one that has retries built in).
> >
> > We've replaced the bundled memcache client with our old one, and it
> > performs much better.
> >
> > On Apr 8, 1:52 pm, Clinton  wrote:
> >
> > > After much effort I upgraded our fairly large Rails app from 2.1 to
> > > 2.3.  After deployment yesterday I noticed an across the board
> > > increase in response times.  It seems that every call to memcache now
> > > takes 10x longer than before.  Here are some example numbers from my
> > > development log (below), with memcache running locally.  We see
> > > similar scale of performance drop in production as well -  average
> > > memcache call before 2ms, now 20ms.  It adds up to a significant hit.
> >
> > > Before Rails 2.3 upgrade:
> >
> > > Cached fragment hit: views/homepage_recent_blog_posts (0.00043)
> > > Cached fragment hit: views/homepage_active_threads (0.00033)
> > > Cached fragment hit: views/homepage_weekly_feature (0.00029)
> > > Cached fragment hit: views/homepage_recent_approved_items (0.00036)
> > > Cached fragment hit: views/homepage_popular_items (0.00037)
> > > Cached fragment hit: views/number_of_members (0.00032)
> >
> > > After Rails 2.3 upgrade:
> >
> > > Cached fragment hit: views/homepage_recent_blog_posts (3.2ms)
> > > Cached fragment hit: views/homepage_active_threads (3.5ms)
> > > Cached fragment hit: views/homepage_weekly_feature (2.9ms)
> > > Cached fragment hit: views/homepage_recent_approved_items (2.8ms)
> > > Cached fragment hit: views/homepage_popular_items (3.1ms)
> > > Cached fragment hit: views/number_of_members (6.7ms)
> >
> > > Before I start delving into the memcache internals in Rails 2.3, has
> > > anyone else experienced this degradation on their apps?  Is there a
> > > magic 'make it fast again' switch that I can flick?
>

I was told by Mike Perham that Rails 2.3+ will automatically use any
memcache-client
gem you have greater than 1.6.4.

Good luck,

-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@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] Voting and Polling

2009-05-24 Thread Chris Mcmillan

I'm pretty new to this so hopefully this isn't a redundant question as I
couldn't seem to find anything on it.  How can I add voting capability
to a site?  I'm getting started building a site with Rails and I would
like people to be able to vote certain things with the options of "yes"
or "no" or "right" or "wrong".  Could someone tell me how I can add this
functionality?

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: Use of global variables...

2009-05-24 Thread Frederick Cheung


On May 24, 10:11 pm, Mk 27  wrote:
> I just googled "Ruby on Rails session variable" and found virtually no
> info, so I still don't know what this refers to.  It does not come up in
> the searchable API either, but I imagine they are in there -- can anyone
> point me to the spot?  Otherwise I will just have to wait for the books
> I requested at the library to roll in next week...

see the Session section at 
http://api.rubyonrails.org/classes/ActionController/Base.html

Fred

>
> thanks again and in advance, MK
>
> *Page caching is definitely not the thing.  I need to keep track of what
> has happened on the page -- ie, all the relevant data is there in front
> of the user.  KEY QUESTION: Where would I start if I wanted to grab and
> parse the "raw" page in it's current state?
>
> I was also thinking I could keep a hidden form, but the former (parse
> the page) would be preferable if possible.
> --
> 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: Use of global variables...

2009-05-24 Thread Mk 27

Matt Jones wrote:

> 
> Not to be snarky, but this seems to describe a session variable
> perfectly...
> 
> --Matt Jones

Well thanks Matt for waiting until I had spent the afternoon re-writing 
my code to use instance variables (just kidding).

Actually, having no professional web dev experience, it occurred to me 
that maybe this is what cookies would be good for*.  At any rate, I was 
probably jumping the gun a little (or getting derailed, haha) in my 
ambitions for learning project #1.

I just googled "Ruby on Rails session variable" and found virtually no 
info, so I still don't know what this refers to.  It does not come up in 
the searchable API either, but I imagine they are in there -- can anyone 
point me to the spot?  Otherwise I will just have to wait for the books 
I requested at the library to roll in next week...

thanks again and in advance, MK

*Page caching is definitely not the thing.  I need to keep track of what 
has happened on the page -- ie, all the relevant data is there in front 
of the user.  KEY QUESTION: Where would I start if I wanted to grab and 
parse the "raw" page in it's current state?

I was also thinking I could keep a hidden form, but the former (parse 
the page) would be preferable if possible.
-- 
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] is f.submit in a form_for newer than submit_tag?

2009-05-24 Thread SpringFlowers AutumnMoon

some books or even the rails api uses

form_for ...
  ...
  submit_tag ...
end

and i found that the Rails 2.3.2 Scaffold uses

f.submit "Go"

instead...  and this is not in the rails api doc.  Is this a new
addition and is it suppose to replace submit_tag?
-- 
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: do you think we should make <%= # comment %> not cause error

2009-05-24 Thread Colin Law
In addition I meant to say that according to the ticket link, <%=# and <%= #
are also not valid erb comments.
Colin

2009/5/24 Colin Law 

> I believe that <% #... %> is not a valid erb comment (no space is allowed
> after %). See
> https://rails.lighthouseapp.com/projects/8994/tickets/1580-whitespace-bug-in-erb-comments-in-rails-222.
> You have to read through the comments to get to the conclusion.
>
> Colin
>
> 2009/5/24 SpringFlowers AutumnMoon 
>
>
>> the code
>>
>>  <% # some code %>
>>
>> will not cause any error, but the code
>>
>>  <%= # some code %>
>>
>> will cause an error.
>>
>> the argument is that the second statement is like
>>
>>  output <<
>>
>> and so it is an error.
>>
>> But I think since
>>
>>  puts "hello"
>>
>> and
>>
>>  puts
>>
>> both can run and cause no error, why not make
>>
>>  <%= # some code %>
>>
>> not cause any error too?  If we have a language / platform that will
>> cause an error when we just comment out code, it is a big issue in the
>> long term, since usually when we comment out something, we won't easily
>> cause a problem and may have a hard time finding what the cause is.
>>
>> for sure, we can change it to
>>
>>  <% # some code %>
>>
>> but we lose the note there that we were going to output the content.
>> When we uncomment the code, we don't know for sure whether it should be
>> <% %> or <%= %> and is prone to mistake again.
>> --
>> 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: what is kENSURE and kEND in error message?

2009-05-24 Thread Colin Law
I think the problem is that seen with most languages, when you have a syntax
error the message may appear to have little to do with the actual error as
the parser has gone off down the wrong track but does not realise this until
it is too late.  Admittedly ruby does seem particularly poor at generating
useful messages.

Colin

2009/5/24 SpringFlowers AutumnMoon 

>
> Roderick van Domburg wrote:
> > SpringFlowers AutumnMoon wrote:
> >> how about the kENSURE ?  and... why the "k" attached in front?  thanks.
> >
> > K is for keyword; the keyword ensure. It seems like you have a
> > ensure..end block without the appropriate "begin".
>
> ah, it actually happened with the <%= # some code %>
>
> --
> 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: what is kENSURE and kEND in error message?

2009-05-24 Thread SpringFlowers AutumnMoon

Roderick van Domburg wrote:
> SpringFlowers AutumnMoon wrote:
>> how about the kENSURE ?  and... why the "k" attached in front?  thanks.
> 
> K is for keyword; the keyword ensure. It seems like you have a 
> ensure..end block without the appropriate "begin".

ah, it actually happened with the <%= # some code %>

-- 
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: do you think we should make <%= # comment %> not cause error

2009-05-24 Thread Colin Law
I believe that <% #... %> is not a valid erb comment (no space is allowed
after %). See
https://rails.lighthouseapp.com/projects/8994/tickets/1580-whitespace-bug-in-erb-comments-in-rails-222.
You have to read through the comments to get to the conclusion.

Colin

2009/5/24 SpringFlowers AutumnMoon 

>
> the code
>
>  <% # some code %>
>
> will not cause any error, but the code
>
>  <%= # some code %>
>
> will cause an error.
>
> the argument is that the second statement is like
>
>  output <<
>
> and so it is an error.
>
> But I think since
>
>  puts "hello"
>
> and
>
>  puts
>
> both can run and cause no error, why not make
>
>  <%= # some code %>
>
> not cause any error too?  If we have a language / platform that will
> cause an error when we just comment out code, it is a big issue in the
> long term, since usually when we comment out something, we won't easily
> cause a problem and may have a hard time finding what the cause is.
>
> for sure, we can change it to
>
>  <% # some code %>
>
> but we lose the note there that we were going to output the content.
> When we uncomment the code, we don't know for sure whether it should be
> <% %> or <%= %> and is prone to mistake again.
> --
> 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: Expired items

2009-05-24 Thread Roderick van Domburg

Youyou Semsem wrote:
> 1. Whenever I want to SELECT from the table, I need to include where
> expiry_date > NOW. If the table Post grows like a monster, I will be in
> trouble. Imagine after 3 years or more. Indexes will be huge too.

Obviously using indices is the easiest. I'm not sure how many posts 
you're expecting, but unless you *know* it'll run into the millions with 
a high percentage of cache misses this sounds like premature 
optimization. First let your RDBMS deal with the size of the indices 
(it'll do fine) and then let your DBA worry about it (he'll cache it 
into RAM and put it on a fast disk).

--
Roderick van Domburg
http://www.nedforce.com
-- 
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: do you think we should make <%= # comment %> not cause e

2009-05-24 Thread Roderick van Domburg

Report it at http://rails.uservoice.com, I'd +1 it!

--
Roderick van Domburg
http://www.nedforce.com
-- 
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: what is kENSURE and kEND in error message?

2009-05-24 Thread Roderick van Domburg

SpringFlowers AutumnMoon wrote:
> how about the kENSURE ?  and... why the "k" attached in front?  thanks.

K is for keyword; the keyword ensure. It seems like you have a 
ensure..end block without the appropriate "begin".

--
Roderick van Domburg
http://www.nedforce.com
-- 
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] do you think we should make <%= # comment %> not cause error

2009-05-24 Thread SpringFlowers AutumnMoon

the code

  <% # some code %>

will not cause any error, but the code

  <%= # some code %>

will cause an error.

the argument is that the second statement is like

  output <<

and so it is an error.

But I think since

  puts "hello"

and

  puts

both can run and cause no error, why not make

  <%= # some code %>

not cause any error too?  If we have a language / platform that will
cause an error when we just comment out code, it is a big issue in the
long term, since usually when we comment out something, we won't easily
cause a problem and may have a hard time finding what the cause is.

for sure, we can change it to

  <% # some code %>

but we lose the note there that we were going to output the content.
When we uncomment the code, we don't know for sure whether it should be
<% %> or <%= %> and is prone to mistake again.
-- 
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: why does this comment create a compile error

2009-05-24 Thread Colin Law
I believe that a comment in erb has to start <%#
Other similar sequences have worked in some versions, or may sometimes work
but are not guaranteed.

Colin

2009/5/24 SpringFlowers AutumnMoon 

>
>
>
> there is a line displayed within 
>
> <%= h @stories.inspect %>
>
> and the output was too long, so i changed it to
>
> <%= #h @stories.inspect %>
>
> <% @stories.each do |s| %>
>  <%= h s.inspect %>
> <% end %>
>
> (commenting out the first line). now the code will fail to compile...
> saying
>
> compile error
> /Users/winterheat/ror/shov2/app/views/stories/index.html.erb:13: syntax
> error, unexpected kENSURE, expecting ')'
> /Users/winterheat/ror/shov2/app/views/stories/index.html.erb:15: syntax
> error, unexpected kEND, expecting ')'
>
> and if i remove that commented line altogether, the code will work. i
> thought in some book, it is said that you can comment out some code in
> ERB like that?
>
> Update: funny if i change it to
>
> <% #h @stories.inspect %>
>
> then it will compile fine... so the displaying of result tag <%= %>
> doesn't like comments, it seems.
> --
> 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: index.erb vs rhtml

2009-05-24 Thread Fernando Perez

> Its like its expecting my views to be .rhtml files, not .html.erb
> files

Cleanup your rubygems, you have a very old version installed, and maybe 
in your Rails. Define in environment.rb:

RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION
-- 
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: can anyone help me with showing lists with conditions?

2009-05-24 Thread Colin Law
Also you will make life much easier for yourself if you stick to the rails
naming conventions, so the column names will be id, name, price, country_id
and id, country_name.

You might find this helpful
http://guides.rubyonrails.org/getting_started.html

Colin

2009/5/24 Hemali Chauhan 

>
> Hi,
>
> You must have defined has_many and belongs_to association for Country
> and Product.
>
> So now you can directly write:
> @product.country.name
>
> -Hemali Chauhan
>
> On May 24, 3:14 pm, Mike75  wrote:
> > hi
> > i'm trying things out with rails, and I'm having trouble with showing
> > a list of products.
> > i hope someone can help me out with this..
> >
> > my tables are simple and it contains the following fields
> >
> > product table : id | Name | Price | Country_id
> > country table : id | CountryName
> >
> > and I input products info with selected id numbers from the "country"
> > table and insert the country.id into products.Country_id.
> >
> > I am trying to show countryName from the country table on the products
> > list.
> >
> > it would be wonderful if anyone can help me out with this..
> >
> > thank you
>
> >
>

--~--~-~--~~~---~--~~
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: index.erb vs rhtml

2009-05-24 Thread rails_n00b

Here is an example of the type of error I am getting when my view
templates are *.html.erb files:

   Showing app/views/contact/show.rhtml where line # raised:
   No such file or directory - /Users/kevin/dev/Ruby/sandbox/
contactlist/app/views/contact/show.rhtml

Its like its expecting my views to be .rhtml files, not .html.erb
files


On May 24, 3:09 pm, Steve Shepherd  wrote:
> Can you post the errors you are getting?
>
> On 5/25/09, rails_n00b  wrote:
>
>
>
>
>
> > I am a total Ruby/RoR n00b having just started reading the 'Ruby on
> > Rails Bible' book two days ago. I've been trying to work out through
> > the introductory 'Your first ruby on rails application' section, but
> > I've run into problems already!
>
> > The book goes on about creating the view templates and naming them
> > with the *.html.erb extension, but I get run-time errors when I use
> > that extension. I have seen some other RoR sites that use the *.rhtml
> > extension so I tried that instead and that seemed to fix my problem.
>
> > But isn't that the old rails file naming convention? I want to use the
> > proper/new convention but I'm not sure what I need to do .. perhaps
> > update Ruby or Rails or ??? on my computer? Or is it something I have
> > misconfigured?
>
> > I'm developing on a Mac and these are the versions of Ruby and RoR I
> > currently have installed:
>
> > ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0]
> > Rails 2.3.2
>
> > If this helps, when I run "gem list" I get this output:
>
> > *** LOCAL GEMS ***
>
> > actionmailer (2.3.2, 1.3.6)
> > actionpack (2.3.2, 1.13.6)
> > actionwebservice (1.2.6)
> > activerecord (2.3.2, 1.15.6)
> > activeresource (2.3.2)
> > activesupport (2.3.2, 1.4.4)
> > acts_as_ferret (0.4.1)
> > capistrano (2.0.0)
> > cgi_multipart_eof_fix (2.5.0, 2.2)
> > daemons (1.0.9, 1.0.7)
> > dnssd (0.6.0)
> > fastthread (1.0.1, 1.0)
> > fcgi (0.8.7)
> > ferret (0.11.4)
> > gem_plugin (0.2.3, 0.2.2)
> > highline (1.2.9)
> > hpricot (0.6)
> > libxml-ruby (0.9.5, 0.3.8.4)
> > mongrel (1.1.4, 1.0.1)
> > needle (1.3.0)
> > net-sftp (1.1.0)
> > net-ssh (1.1.2)
> > rails (2.3.2, 1.2.6)
> > rake (0.8.7, 0.7.3)
> > RedCloth (3.0.4)
> > ruby-openid (1.1.4)
> > ruby-yadis (0.3.4)
> > rubynode (0.1.3)
> > sqlite3-ruby (1.2.1)
> > termios (0.9.4)
>
> > Any help would be greatly appreciated!
>
> --
> 
> Steve Shepherd
> Mob:+64  (0) 27 4338154
> Email: sargs...@gmail.com
> Analyst
--~--~-~--~~~---~--~~
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] why does this comment create a compile error

2009-05-24 Thread SpringFlowers AutumnMoon



there is a line displayed within 

<%= h @stories.inspect %>

and the output was too long, so i changed it to

<%= #h @stories.inspect %>

<% @stories.each do |s| %>
  <%= h s.inspect %>
<% end %>

(commenting out the first line). now the code will fail to compile...
saying

compile error
/Users/winterheat/ror/shov2/app/views/stories/index.html.erb:13: syntax
error, unexpected kENSURE, expecting ')'
/Users/winterheat/ror/shov2/app/views/stories/index.html.erb:15: syntax
error, unexpected kEND, expecting ')'

and if i remove that commented line altogether, the code will work. i
thought in some book, it is said that you can comment out some code in
ERB like that?

Update: funny if i change it to

<% #h @stories.inspect %>

then it will compile fine... so the displaying of result tag <%= %>
doesn't like comments, it seems.
-- 
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] what is kENSURE and kEND in error message?

2009-05-24 Thread SpringFlowers AutumnMoon

I sometimes get an error on the page as:

compile error
/Users/jian/ror/shov2/app/views/stories/index.html.erb:13: syntax
error, unexpected kENSURE, expecting ')'
/Users/jian/ror/shov2/app/views/stories/index.html.erb:15: syntax
error, unexpected kEND, expecting ')'

the kEND, i can guess that it is End... so it means End of file but
unexpected, there should be a ')'.

how about the kENSURE ?  and... why the "k" attached in front?  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: Anybody interesting in sharing some rails tips?

2009-05-24 Thread Steve Shepherd
@Gavin

I would suggest harvesting tips from this forum.
There are hundreds and hundreds of replies to questions in here.
Not sure though doubling up serves a better purpose than looking through the
forums though.

The biggest problem with ror is it keeps changing so tips can go out of
date.

just my two cents worth

On 5/25/09, GS  wrote:
>
>
> having just quickly glanced at the homepage, have already gotten at
> least 2 immediately useful tips.
>
> bookmarked it and seems promising for the longer term.
>
> thanks!
> -Gabe
>
>
>
> On May 22, 4:18 am, Gavin  wrote:
> > Hi all,
> >
> > I've just lauched a site called handy rails tips.  I built this app
> > because I fancied having someplace to share rails ideas and also write
> > about new stuff I've discovered.
> >
> > I figured there would be other rails users in the same boat as me so
> > the site is open to anyone who wants to write.
> > Just create an account and log in.
> >
> > I hope at least some of you find it useful
> >
> > handyrailstips.com
> >
> > Thanks
> >
> > Gavin
> >
>


-- 

Steve Shepherd
Mob:+64  (0) 27 4338154
Email: sargs...@gmail.com
Analyst

--~--~-~--~~~---~--~~
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 to edit a pluggin? (acts_as_taggable_on)

2009-05-24 Thread Steve Shepherd
Try using the IN sql operator.
Unless you are using wildcards i think in should work.

ie   name IN ('fish','frog')

You will need to change your code.


On 5/25/09, aupayo  wrote:
>
>
> In case someone has the same problem:
>
> I have executed:
> rake gems:unpack
> So now the plugin is in the vendors/gem directory inside my rails
> proyect and when I edit it there, the changes take effect.
>
> However I haven't been able to obtain the functionality that I was
> looking for in acts_as_taggable_on with the change I made...any ideas?
>
>
>
> On 23 mayo, 19:27, aupayo  wrote:
> > Hello,
> >
> > I'm trying to modificate the acts_as_taggable_on pluggin, so when you
> > search various tags (Eg: User.tagged_with("fish, cat", :on
> > => :animals), it looks for users with BOTH tags, not just one of them.
> >
> > I have edited the file acts_as_taggable_on.rb and I have changed the
> > line:
> > "conditions << tags.map { |t| sanitize_sql(["#{tags_alias}.name
> > LIKE ?", t]) }.join(" OR ")"
> > with
> > ""conditions << tags.map { |t| sanitize_sql(["#{tags_alias}.name
> > LIKE ?", t]) }.join(" AND ")".
> > but when I execute the search, the sql sentence that is executed is
> > the same than before.
> >
> > I just restarted the console after doing the changes, do I have to do
> > something else so the changes take effect? (I installed the plugin
> > through GemPlugins)
> >
> > Or maybe I'm editing the wrong line?...if someone has done this before
> > please correct me if I'm wrong!
> >
> > Thanks!
> >
>


-- 

Steve Shepherd
Mob:+64  (0) 27 4338154
Email: sargs...@gmail.com
Analyst

--~--~-~--~~~---~--~~
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: index.erb vs rhtml

2009-05-24 Thread Steve Shepherd
Can you post the errors you are getting?

On 5/25/09, rails_n00b  wrote:
>
>
> I am a total Ruby/RoR n00b having just started reading the 'Ruby on
> Rails Bible' book two days ago. I've been trying to work out through
> the introductory 'Your first ruby on rails application' section, but
> I've run into problems already!
>
> The book goes on about creating the view templates and naming them
> with the *.html.erb extension, but I get run-time errors when I use
> that extension. I have seen some other RoR sites that use the *.rhtml
> extension so I tried that instead and that seemed to fix my problem.
>
> But isn't that the old rails file naming convention? I want to use the
> proper/new convention but I'm not sure what I need to do .. perhaps
> update Ruby or Rails or ??? on my computer? Or is it something I have
> misconfigured?
>
> I'm developing on a Mac and these are the versions of Ruby and RoR I
> currently have installed:
>
> ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0]
> Rails 2.3.2
>
> If this helps, when I run "gem list" I get this output:
>
> *** LOCAL GEMS ***
>
> actionmailer (2.3.2, 1.3.6)
> actionpack (2.3.2, 1.13.6)
> actionwebservice (1.2.6)
> activerecord (2.3.2, 1.15.6)
> activeresource (2.3.2)
> activesupport (2.3.2, 1.4.4)
> acts_as_ferret (0.4.1)
> capistrano (2.0.0)
> cgi_multipart_eof_fix (2.5.0, 2.2)
> daemons (1.0.9, 1.0.7)
> dnssd (0.6.0)
> fastthread (1.0.1, 1.0)
> fcgi (0.8.7)
> ferret (0.11.4)
> gem_plugin (0.2.3, 0.2.2)
> highline (1.2.9)
> hpricot (0.6)
> libxml-ruby (0.9.5, 0.3.8.4)
> mongrel (1.1.4, 1.0.1)
> needle (1.3.0)
> net-sftp (1.1.0)
> net-ssh (1.1.2)
> rails (2.3.2, 1.2.6)
> rake (0.8.7, 0.7.3)
> RedCloth (3.0.4)
> ruby-openid (1.1.4)
> ruby-yadis (0.3.4)
> rubynode (0.1.3)
> sqlite3-ruby (1.2.1)
> termios (0.9.4)
>
> Any help would be greatly appreciated!
>
> >
>


-- 

Steve Shepherd
Mob:+64  (0) 27 4338154
Email: sargs...@gmail.com
Analyst

--~--~-~--~~~---~--~~
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: Problems with testing/Wrong table columns

2009-05-24 Thread krani

Thank you!

For whatever reason there were faulty definitions in the fixtures of
other models.

Now it works :)

Thanks everybody who tried to help me!


On 24 Mai, 20:25, Frederick Cheung  wrote:
> On May 24, 7:19 pm, krani  wrote:
>
> > Unfortunately I don't understand what rails want to tell me with this
> > trace...
>
> > I don't think that there is a problem in schema.rb. This is the
> > definition for the component model:
>
> >   create_table "components", :force => true do |t|
> >     t.integer  "project_id"
> >     t.integer  "category_id"
> >     t.string   "name"
> >     t.text     "text"
> >     t.datetime "created_at"
> >     t.datetime "updated_at"
> >   end
>
> The error occurs when loading the fixtures for brand. You should
> probably look at the fixtures file or schema for that table.
>
> Fred
--~--~-~--~~~---~--~~
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: can anyone help me with showing lists with conditions?

2009-05-24 Thread Hemali Chauhan

Hi,

You must have defined has_many and belongs_to association for Country
and Product.

So now you can directly write:
@product.country.name

-Hemali Chauhan

On May 24, 3:14 pm, Mike75  wrote:
> hi
> i'm trying things out with rails, and I'm having trouble with showing
> a list of products.
> i hope someone can help me out with this..
>
> my tables are simple and it contains the following fields
>
> product table : id | Name | Price | Country_id
> country table : id | CountryName
>
> and I input products info with selected id numbers from the "country"
> table and insert the country.id into products.Country_id.
>
> I am trying to show countryName from the country table on the products
> list.
>
> it would be wonderful if anyone can help me out with this..
>
> thank you

--~--~-~--~~~---~--~~
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: Problems with testing/Wrong table columns

2009-05-24 Thread Frederick Cheung


On May 24, 7:19 pm, krani  wrote:

> Unfortunately I don't understand what rails want to tell me with this
> trace...
>
> I don't think that there is a problem in schema.rb. This is the
> definition for the component model:
>
>   create_table "components", :force => true do |t|
>     t.integer  "project_id"
>     t.integer  "category_id"
>     t.string   "name"
>     t.text     "text"
>     t.datetime "created_at"
>     t.datetime "updated_at"
>   end
>

The error occurs when loading the fixtures for brand. You should
probably look at the fixtures file or schema for that table.

Fred


--~--~-~--~~~---~--~~
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] Rails 2.3 Localized Views issues with IE

2009-05-24 Thread chris

Hey all,

Having issues under IE with localized views... whenever it tries to
get a xxx.fr.html.erb IE spits out a File Download Security Warning
dialog ?!?
Firefox works fine... and I cant seem to find any info on the web of
issues of this kind... I'm seeing these problems locally and on my
VPS.

My Env.:
Rails 2.3.2
RubyGems 1.3.2
Ruby 1.8.6

Thanks,
Chris

--~--~-~--~~~---~--~~
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: Expired items

2009-05-24 Thread Frederick Cheung



On May 24, 6:17 pm, Youyou Semsem 
wrote:
> Hi guys,
>
> I have a model Post which has a expiry_date. I want to know what is the
> best way to manage scalability in this case. 2 options:
>
> 1. Whenever I want to SELECT from the table, I need to include where
> expiry_date > NOW. If the table Post grows like a monster, I will be in
> trouble. Imagine after 3 years or more. Indexes will be huge too.
>
You could have a table with millions of rows and such a query would be
fast (as long of course as you had an index on the expiry_date
column). Not to say that moving expired posts somewhere else wouldn't
necessarily be a bad idea but certainly not something I would do
preemptively

Fred
> 2. Have a trigger, cron job, or a plugin (if it exists) that would go
> around the table and move expired items to a new table Post_Archive.
> That way, I maintain only current Posts in my main table, which implies
> that over 3 years I won't be as bad as option 1.
>
> Any help? comments from your experience?
>
> Thanks,
> Youssef
> --
> 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: Problems with testing/Wrong table columns

2009-05-24 Thread krani

Hi

thanks for your help :)

The complete trace:

D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/connection_adapters/
abstract_adapter.rb:188:in `log'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/connection_adapters/
mysql_adapter.rb:309:in `execute'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/connection_adapters/abstract/
database_statements.rb:147:in `insert_fixture'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/fixtures.rb:640:in
`insert_fixtures'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/fixtures.rb:577:in `each'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/fixtures.rb:577:in
`insert_fixtures'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/fixtures.rb:520:in
`create_fixtures'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/fixtures.rb:520:in `each'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/fixtures.rb:520:in
`create_fixtures'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/connection_adapters/abstract/
database_statements.rb:66:in `transaction'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/fixtures.rb:518:in
`create_fixtures'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/connection_adapters/
mysql_adapter.rb:254:in `disable_referential_integrity'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/fixtures.rb:509:in
`create_fixtures'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/base.rb:1398:in `silence'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/fixtures.rb:508:in
`create_fixtures'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/fixtures.rb:964:in
`load_fixtures'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/fixtures.rb:930:in
`setup_fixtures'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/callbacks.rb:178:in `send'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/callbacks.rb:178:in
`evaluate_method'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/callbacks.rb:166:in `call'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/callbacks.rb:90:in `run'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/callbacks.rb:90:in `each'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/callbacks.rb:90:in `send'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/callbacks.rb:90:in `run'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/callbacks.rb:277:in
`run_callbacks'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/testing/setup_and_teardown.rb:
58:in `run'

Unfortunately I don't understand what rails want to tell me with this
trace...

I don't think that there is a problem in schema.rb. This is the
definition for the component model:

  create_table "components", :force => true do |t|
t.integer  "project_id"
t.integer  "category_id"
t.string   "name"
t.text "text"
t.datetime "created_at"
t.datetime "updated_at"
  end

bye
krani

On 20 Mai, 18:28, Colin Law  wrote:
> I did not look carefully enough at the output, I see now that it has
> actually started the test and is in test_test_should_create_a_component.
> You should be able to see from the trace where in your application it
> generated the faulty sql, though sometimes you have to examine the trace
> carefully to find the bits that are in your code and the bits that are in
> Rails.  This might give you a clue.  If you can't work it out post the
> trace.
>
> It would also be worth having a look at db/schema.rb just to check what it
> thinks the tables should look like.  Post that also if necessary.
>
> Colin
>
> 2009/5/20 krani 
>
>
>
> > Hi,
>
> > thanks for your reply
>
> > I don't think that there is a problem with my fixtures. I have only
> > one:
>
> > one:
> >   project_id:1
> >  category_id:1
> >   name:
> >  text:KN Airintake Kit
> >  created_at:
> >  updated_at:
>
> > regards
> > krani
>
> > On 19 Mai, 22:33, Colin Law  wrote:
> > > I am not sure but could t

[Rails] Re: != not working in search query (thinking sphinx)

2009-05-24 Thread Frederick Cheung



On May 24, 5:22 pm, Sam Ginko 
wrote:
> Still not working. I tried
>
> @ allPost = Post.search params[:search], :conditions
> =>["account_status.to_i != ?", 0]
>
> @ allPost = Post.search params[:search], :conditions
> =>"account_status.to_i != 0"
>

Have a look at the documentation for sphinx/thinking sphinx - this
isn't activerecord any more, or SQL. To quote the thinking sphinx
docs:

> Please keep in mind that Sphinx does not support SQL comparison operators – 
> it has its own query language. The
> :conditions option must be a hash, with each key a field and each value a 
> string.

In addition, :conditions is for doing full text searches against
specific columns you have indexed - for filtering on attribute values
you need to use the :with option.

Fred

> Mk 27 wrote:
> > Looks like I am one step ahead of you Sam, I learned this one yesterday:
>
> >http://www.ruby-forum.com/topic/187676#new
>
> > Look a few posts down for the series of "67 != 67"
>
> > Anyway, the problem is that w/ a HTTP request everything is received as
> > a string. So:
>
> > account_status.to_i
>
> --
> 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: beginner

2009-05-24 Thread Frederick Cheung



On May 24, 6:29 pm, Freddy Andersen  wrote:
> if params[:checkbox]
>
> This checks if that params is true(true/false, 1/0)

both 1 and 0 are true in ruby :-)
If you are doing this by hand you will need to compare params
[:checkbox] to the value that gets submitted. if you are using the
check_box helper then by default the value will be "0" or
"1" (strings, not integers). If you are using check_box_tag or
crafting the html by hand then it is slightly more troublesome as if
the check box is not ticked there will be no value in the params hash.
If you are using the check_box helper it might be appropriate to just
pass the appropriate part of the params hash to update_attributes.

Fred


 or not, but how
> did you do you checkbox code? If its just a form_for .. do |f|
> f.checkbox(:checkbox) you should be ok.
--~--~-~--~~~---~--~~
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 to pass arguments to functions in callbacks in model ?

2009-05-24 Thread Erdwin Lianata

What about ...

def update_something(value=false)
   # ..
end

def after_save
   update_something(true)
end


Or use instance variable as conditional state instead of passing 
variable to a function called from macro (i.e after_save)


Arpit Jain wrote:
> I need to pass attributes to the function called in callback in rails 
> model.  For example,
> 
> after_save :update_something
> after_destroy :update_something, true  #true is the argument that I need 
> to pass
> 
> private
> def update_something(value = false)
>   #...
> end
> 
> 
> I found a way to do it like this
> 
> after_save :update_something
> after_destroy {|record| record.update_something(true)}
> 
> But in this case, I need to make the function update_something public, 
> which I don't want to do.
> 
> Any help ?
> 
> 
> -- 
> Arpit Jain

--~--~-~--~~~---~--~~
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] index.erb vs rhtml

2009-05-24 Thread rails_n00b

I am a total Ruby/RoR n00b having just started reading the 'Ruby on
Rails Bible' book two days ago. I've been trying to work out through
the introductory 'Your first ruby on rails application' section, but
I've run into problems already!

The book goes on about creating the view templates and naming them
with the *.html.erb extension, but I get run-time errors when I use
that extension. I have seen some other RoR sites that use the *.rhtml
extension so I tried that instead and that seemed to fix my problem.

But isn't that the old rails file naming convention? I want to use the
proper/new convention but I'm not sure what I need to do .. perhaps
update Ruby or Rails or ??? on my computer? Or is it something I have
misconfigured?

I'm developing on a Mac and these are the versions of Ruby and RoR I
currently have installed:

ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0]
Rails 2.3.2

If this helps, when I run "gem list" I get this output:

*** LOCAL GEMS ***

actionmailer (2.3.2, 1.3.6)
actionpack (2.3.2, 1.13.6)
actionwebservice (1.2.6)
activerecord (2.3.2, 1.15.6)
activeresource (2.3.2)
activesupport (2.3.2, 1.4.4)
acts_as_ferret (0.4.1)
capistrano (2.0.0)
cgi_multipart_eof_fix (2.5.0, 2.2)
daemons (1.0.9, 1.0.7)
dnssd (0.6.0)
fastthread (1.0.1, 1.0)
fcgi (0.8.7)
ferret (0.11.4)
gem_plugin (0.2.3, 0.2.2)
highline (1.2.9)
hpricot (0.6)
libxml-ruby (0.9.5, 0.3.8.4)
mongrel (1.1.4, 1.0.1)
needle (1.3.0)
net-sftp (1.1.0)
net-ssh (1.1.2)
rails (2.3.2, 1.2.6)
rake (0.8.7, 0.7.3)
RedCloth (3.0.4)
ruby-openid (1.1.4)
ruby-yadis (0.3.4)
rubynode (0.1.3)
sqlite3-ruby (1.2.1)
termios (0.9.4)

Any help would be greatly appreciated!

--~--~-~--~~~---~--~~
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: include path gems hostgator

2009-05-24 Thread Aldo Urem

Luca Roma wrote:
> i buyed a web hosting. i installed some gems.
> in the hostgator's instructions there is write:
> 
> Using Your Ruby Gem(s)
> 
> You will need to add /home/nerto/ruby/gems to the include path.
> You can do this by adding the following code to your script:
> 
> $:.push("/home/nerto/ruby/gems")
> 
> but i don't understand where i must to put it
> 
> Can you help me?
> thanks


Same problem here.

I don't know where to put it?

-- 
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: beginner

2009-05-24 Thread Freddy Andersen

if params[:checkbox]

This checks if that params is true(true/false, 1/0) or not, but how
did you do you checkbox code? If its just a form_for .. do |f|
f.checkbox(:checkbox) you should be ok.
--~--~-~--~~~---~--~~
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: sql Rand() returns same result

2009-05-24 Thread Matt Jones

You may be getting stuck in the query cache. Try this:

Model.uncached { Model.find(:first, :order => "RAND()") }

Which will shut off query caching for that call.

--Matt Jones


On May 23, 1:35 pm, jg  wrote:
> I have a method that calls Model.find(:first, :order => "RAND()")
> twice. I want it to return two different results but it always returns
> the same thing twice. Is there some kind of sql caching at work here?
> If so, can I disable for this method?
>
> thanks!
>
> Jason
--~--~-~--~~~---~--~~
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: Use of global variables...

2009-05-24 Thread Matt Jones

On May 24, 8:18 am, Mk 27  wrote:
> ie, you will have to write that data to a file of some sort, and use
> some kind of per user key to identify it.  Which sucks, but I guess that
> is life.
>

Not to be snarky, but this seems to describe a session variable
perfectly...

--Matt Jones


--~--~-~--~~~---~--~~
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] Expired items

2009-05-24 Thread Youyou Semsem

Hi guys,

I have a model Post which has a expiry_date. I want to know what is the
best way to manage scalability in this case. 2 options:

1. Whenever I want to SELECT from the table, I need to include where
expiry_date > NOW. If the table Post grows like a monster, I will be in
trouble. Imagine after 3 years or more. Indexes will be huge too.

2. Have a trigger, cron job, or a plugin (if it exists) that would go
around the table and move expired items to a new table Post_Archive.
That way, I maintain only current Posts in my main table, which implies
that over 3 years I won't be as bad as option 1.

Any help? comments from your experience?

Thanks,
Youssef
-- 
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: Rails 2.3 memcache performance drop

2009-05-24 Thread erik

Hi-
  Could tell me how you replaced it?  I just installed the newest gem
1.7.2 and would like to use it with rails.  What's the procedure to
remove the bundled gem?
Thanks.
Erik

On Apr 8, 8:14 pm, Ryan Allen  wrote:
> It turned out that the bundled memcache client that came with
> ActiveSupport (1.6.5) was, for some reason, _much_ slower than the one
> we were using before the Rails 2.3 upgrade (we were using fiveruns-
> memcache-client (1.5.0.5), the one that has retries built in).
>
> We've replaced the bundled memcache client with our old one, and it
> performs much better.
>
> On Apr 8, 1:52 pm, Clinton  wrote:
>
> > After much effort I upgraded our fairly large Rails app from 2.1 to
> > 2.3.  After deployment yesterday I noticed an across the board
> > increase in response times.  It seems that every call to memcache now
> > takes 10x longer than before.  Here are some example numbers from my
> > development log (below), with memcache running locally.  We see
> > similar scale of performance drop in production as well -  average
> > memcache call before 2ms, now 20ms.  It adds up to a significant hit.
>
> > Before Rails 2.3 upgrade:
>
> > Cached fragment hit: views/homepage_recent_blog_posts (0.00043)
> > Cached fragment hit: views/homepage_active_threads (0.00033)
> > Cached fragment hit: views/homepage_weekly_feature (0.00029)
> > Cached fragment hit: views/homepage_recent_approved_items (0.00036)
> > Cached fragment hit: views/homepage_popular_items (0.00037)
> > Cached fragment hit: views/number_of_members (0.00032)
>
> > After Rails 2.3 upgrade:
>
> > Cached fragment hit: views/homepage_recent_blog_posts (3.2ms)
> > Cached fragment hit: views/homepage_active_threads (3.5ms)
> > Cached fragment hit: views/homepage_weekly_feature (2.9ms)
> > Cached fragment hit: views/homepage_recent_approved_items (2.8ms)
> > Cached fragment hit: views/homepage_popular_items (3.1ms)
> > Cached fragment hit: views/number_of_members (6.7ms)
>
> > Before I start delving into the memcache internals in Rails 2.3, has
> > anyone else experienced this degradation on their apps?  Is there a
> > magic 'make it fast again' switch that I can flick?
--~--~-~--~~~---~--~~
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] beginner

2009-05-24 Thread Luis Sp

Hello everyone,
I'm new to RoR, and I have a silly problem I can't solve.
I have a User class, with some attributes (login, password, online..).
In the login form, I have a checkbox. I want to change the value of the
online attribute if this checkbox is checked. I know it must be
something like (if params[:checkboxname]==true).
Does anyone how to do that?

thanks a lot
-- 
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 to edit a pluggin? (acts_as_taggable_on)

2009-05-24 Thread aupayo

In case someone has the same problem:

I have executed:
rake gems:unpack
So now the plugin is in the vendors/gem directory inside my rails
proyect and when I edit it there, the changes take effect.

However I haven't been able to obtain the functionality that I was
looking for in acts_as_taggable_on with the change I made...any ideas?


On 23 mayo, 19:27, aupayo  wrote:
> Hello,
>
> I'm trying to modificate the acts_as_taggable_on pluggin, so when you
> search various tags (Eg: User.tagged_with("fish, cat", :on
> => :animals), it looks for users with BOTH tags, not just one of them.
>
> I have edited the file acts_as_taggable_on.rb and I have changed the
> line:
> "conditions << tags.map { |t| sanitize_sql(["#{tags_alias}.name
> LIKE ?", t]) }.join(" OR ")"
> with
> ""conditions << tags.map { |t| sanitize_sql(["#{tags_alias}.name
> LIKE ?", t]) }.join(" AND ")".
> but when I execute the search, the sql sentence that is executed is
> the same than before.
>
> I just restarted the console after doing the changes, do I have to do
> something else so the changes take effect? (I installed the plugin
> through GemPlugins)
>
> Or maybe I'm editing the wrong line?...if someone has done this before
> please correct me if I'm wrong!
>
> 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: != not working in search query (thinking sphinx)

2009-05-24 Thread Sam Ginko

Still not working. I tried


@ allPost = Post.search params[:search], :conditions 
=>["account_status.to_i != ?", 0]

@ allPost = Post.search params[:search], :conditions 
=>"account_status.to_i != 0"


Mk 27 wrote:
> Looks like I am one step ahead of you Sam, I learned this one yesterday:
> 
> http://www.ruby-forum.com/topic/187676#new
> 
> Look a few posts down for the series of "67 != 67"
> 
> Anyway, the problem is that w/ a HTTP request everything is received as 
> a string. So:
> 
> account_status.to_i

-- 
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: Anybody interesting in sharing some rails tips?

2009-05-24 Thread GS

having just quickly glanced at the homepage, have already gotten at
least 2 immediately useful tips.

bookmarked it and seems promising for the longer term.

thanks!
-Gabe


On May 22, 4:18 am, Gavin  wrote:
> Hi all,
>
> I've just lauched a site called handy rails tips.  I built this app
> because I fancied having someplace to share rails ideas and also write
> about new stuff I've discovered.
>
> I figured there would be other rails users in the same boat as me so
> the site is open to anyone who wants to write.
> Just create an account and log in.
>
> I hope at least some of you find it useful
>
> handyrailstips.com
>
> Thanks
>
> Gavin
--~--~-~--~~~---~--~~
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: belongs_to not saving foreign key

2009-05-24 Thread Sean K

You are correct, Jeff, setting the author using the create method on a
has_many works:

  test "something" do
a1 = Author.create! :name => 'author 1'
b = a1.books.create! :title => 'rails'
a2 = Author.create! :name => 'author 2'
b.update_attributes! :author_id => a2.id
assert_equal a2.id, b.author_id
  end

And so does setting the author via the foreign key:

  test "something" do
a1 = Author.create! :name => 'author 1'
b = Book.create! :title => 'rails', :author_id => a1
a2 = Author.create! :name => 'author 2'
b.update_attributes! :author_id => a2.id
assert_equal a2.id, b.author_id
  end

So why doesn't it like it when the belongs_to is used?  Seems odd.

On May 24, 6:04 am, Jeff Schoolcraft 
wrote:
> your Author should :have_many :books
> You also want to do something like this:
>
> dave = Author.create(:name => 'Dave Thomas')
> pickaxe = dave.books.build(:title => 'Programming Ruby 1.9')
>
>
>
> On Sun, May 24, 2009 at 3:46 AM, Sean K  wrote:
>
> > Under Rails 2.3.2 using a completely brand new project, I have 2
> > models:
>
> > class Author < ActiveRecord::Base
> >  # name:string
> > end
>
> > class Book < ActiveRecord::Base
> >  # title:string
> >  belongs_to :author # author_id
> > end
>
> > And a simple test where i create a Book with an Author using the
> > belongs_to and then update the foreign key directly:
>
> > require 'test_helper'
>
> > class BookTest < ActiveSupport::TestCase
> >  test "foreign key updating" do
> >    a1 = Author.create! :name => 'author 1'
> >    b = Book.create! :title => 'rails', :author => a1
> >    a2 = Author.create! :name => 'author 2'
> >    b.update_attributes! :author_id => a2.id
> >    assert_equal a2.id, b.author_id  # author_id is still a1.id!
> >  end
> > end
>
> > The test fails on the last line.   Am i doing something wrong or is
> > this expected behaviour?
>
> --
> Jeff Schoolcrafthttp://thequeue.net/blog/
--~--~-~--~~~---~--~~
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: Preloading database tables

2009-05-24 Thread Marnen Laibow-Koser

Roderick van Domburg wrote:
[...]
> 
> You mean seeding? There's a couple of plugins for this, like seed_fu. 

Yup.  There's also a Railscast on the subject.

> You could also use fixtures and load those using rake db:fixtures:load.

Yeah, but that's kind of ugly for large amounts of seed data...

> Finally, seeding will be supported out of the box in upcoming Rails 
> releases.

Really?  Cool!  That's good news.
> 
> --
> Roderick van Domburg
> http://www.nedforce.com

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] Re: belongs_to not saving foreign key

2009-05-24 Thread Sean K

Thanks for the replies.  However, changing the Author to:

class Author < ActiveRecord::Base
  has_many :books
end

doesn't change the outcome of the test.  The problem that i'm having
seems to be that the foreign key (Book.author_id) is not being updated
by update_attributes.  This smells like a bug to me.

On May 24, 6:08 am, fRAnKEnSTEin  wrote:
> Jeff Schoolcraft is right.  Your Author model should have this line
>
>  :has_many :books
>
>  In faat you should specify all the db relations in your model files,
> all of them.
>
> cheers
--~--~-~--~~~---~--~~
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: != not working in search query (thinking sphinx)

2009-05-24 Thread Mk 27

Looks like I am one step ahead of you Sam, I learned this one yesterday:

http://www.ruby-forum.com/topic/187676#new

Look a few posts down for the series of "67 != 67"

Anyway, the problem is that w/ a HTTP request everything is received as 
a string. So:

account_status.to_i


-- 
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] != not working in search query (thinking sphinx)

2009-05-24 Thread Sam Ginko

I have a int field in my database and would like to check if it's not
0. Apparently the != in the condition is not working. I'm I doing
something wrong? I tried different ways with no luck. Can anyone help?

these are the options I tried

@allPost = Post.search params[:search], :conditions => 
["account_status
!= 0"]
@ allPost = Post.search params[:search], :conditions =>

["account_status != ?", 0]
@ allPost = Post.search params[:search], :conditions =>

["account_status IS NOT ?", 0]
@ allPost = Post.search params[:search], :conditions =>

["account_status < ?", 1]

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: sql Rand() returns same result

2009-05-24 Thread Hassan Schroeder

On Sat, May 23, 2009 at 10:06 PM, E. Litwin  wrote:

Speaking strictly from a MySQL perspective --

> First of all, I'm assuming you are calling rand() (lowercase).

Case isn't significant.

> I don't really understand what you are trying to randomize in your
> order parameter.
> You should probably get the count of the records in your table and
> generate a random number between 1 and that count. Then use offset to

? The syntax below works just fine to return a random instance of
Model.

>> I have a method that calls Model.find(:first, :order => "RAND()")
>> twice. I want it to return two different results but it always returns
>> the same thing twice.

What it *doesn't* do is guarantee that any two randomly selected
instances won't be the same :-)

Quick example:
>> (1..20).each do
?> @up = UserProfile.find(:first, :order => "rand()")
>> puts @up.id
>> end
8
8
11
1
5
1
13
13
2
6
17
5
4
9
6
17
8
10
7
5
=> 1..20

If the two really need to be different, you'll have to address that with
application logic.

FWIW,
-- 
Hassan Schroeder  hassan.schroe...@gmail.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: why does form_for @story has to have Story as RESTful

2009-05-24 Thread Denis Haskin

"can Story be not RESTful?  Can it be a form for non-RESTful data?"

Sure.  Keep in mind one of the Rails tenets: "convention over 
configuration".

Take a look at the HTML generated by form_for in the various REST 
contexts (e.g. new, edit).  *By default* it Does The Right Thing if 
you're using RESTful resources.

But there's nothing to stop you from overriding the configuration, e.g.:

form_for @order, :url => checkout_details_path, :method => :put do |f|

and having a route to support it.

dwh



SpringFlowers AutumnMoon wrote:
> it seems that when we use
>
>   form_for @story do |f|
>
> then Story has to be a RESTful resource and it has to be
>
>   map.resources :stories
>
> in the routes.rb?
>
> can Story be not RESTful?  Can it be a form for non-RESTful data?
>   

--~--~-~--~~~---~--~~
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: Preloading database tables

2009-05-24 Thread Roderick van Domburg

ms wrote:
> Thanks for your answer, I'll explain: I've got my migrations where I
> can set up the table layout. Afterwards I want to fill this database
> with some predefined records. These records should lay somewhere else
> in simple text files, CSV, XML or whatever. It's just about to divide
> the table definitions and the data I want to add directly after the
> creation.

You mean seeding? There's a couple of plugins for this, like seed_fu. 
You could also use fixtures and load those using rake db:fixtures:load. 
Finally, seeding will be supported out of the box in upcoming Rails 
releases.

--
Roderick van Domburg
http://www.nedforce.com
-- 
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] why does form_for @story has to have Story as RESTful

2009-05-24 Thread SpringFlowers AutumnMoon

it seems that when we use

  form_for @story do |f|

then Story has to be a RESTful resource and it has to be

  map.resources :stories

in the routes.rb?

can Story be not RESTful?  Can it be a form for non-RESTful data?
-- 
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] does map.resources :stories immediately make Story RESTful?

2009-05-24 Thread SpringFlowers AutumnMoon



I was reading Simply Rails by Patrick Lenz... maybe I missed something,
it seems that whenever we put

map.resources :stories

in routes.rb

then immediately, the controller will have special conventions and now
Story is a RESTful resource? Maybe the author used the word resource but
didn't mention that it is RESTful but they are the same thing?
-- 
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: Preloading database tables

2009-05-24 Thread Mk 27

ms wrote:
> Thanks for your answer, I'll explain: I've got my migrations where I
> can set up the table layout. Afterwards I want to fill this database
> with some predefined records. These records should lay somewhere else
> in simple text files, CSV, XML or whatever. It's just about to divide
> the table definitions and the data I want to add directly after the
> creation.
> 
> Thanks for your help,
> ms

You can create a database anyway you like and use it to replace the 
(empty) one initially created -- as long as all the table and column 
names match, of course.  You can even do that while the server is 
running. Also, every table must have a column "id" which is the INTEGER 
PRIMARY KEY, and this should be a unique number for each row.  Table 
names should correspond to controller class names.  They should be 
plural and capitalized*, eg, if you have an app/views/document (and an 
app/controllers/document_controller.rb), you will need a table in your 
database called Documents which corresponds to the entry in 
db/schema.rb.

Is that what you mean?


*they may not have to be since they are not in the schema -- anyway, 
when I've done this they were capitalized and it works fine.
-- 
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] ActiveRecord changes Logger formatting

2009-05-24 Thread RobR

Why does my Logger formatting change after I "require
'active_record'"?

irb(main):001:0> require 'logger'
=> true
irb(main):002:0> $logger = Logger::new STDOUT
=> #, @level=0, @progname=nil,
@logdev=#, @dev=#, @shift_size=nil>>
irb(main):003:0>
irb(main):004:0* $logger.info{ "Expected log line style" }
I, [2009-05-24T06:58:44.599720 #22050]  INFO -- : Expected log line
style
=> true
irb(main):005:0>
irb(main):006:0* require 'active_record'
=> true
irb(main):007:0> $logger.info{ "Why did AR change my log line
style?" }
Why did AR change my log line style?
=> true
irb(main):008:0>

Furthermore, how does one specify a user defined Logger format style?
I need to provide my Log lines in a format consistent with our other
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] Re: why do we use form_for @story do |f| when there is no loop?

2009-05-24 Thread SpringFlowers AutumnMoon

Marnen Laibow-Koser wrote:

>> so i think the block method will save the begin_form and end_form 
>> because it automatically add the begin and end before calling the block. 
>> is that the main benefit?
> 
> Oh, now I see what you mean about the syntax.  Yes, that's sort of it. 
> Read more about blocks in Ruby.

yes, what i meant was something like

with_model_give_form (@story) do |f|
  f.begin_form
  f.text_field :name
  f.end_form
end

except the begin_form and end_form can be called within 
"with_model_give_form", so it can become

with_model_give_form (@story) do |f|
  f.text_field :name
end

so it is now the same thing as form_for

-- 
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: why do we use form_for @story do |f| when there is no loop?

2009-05-24 Thread Marnen Laibow-Koser

SpringFlowers AutumnMoon wrote:
[...]
> can i use something like:  (just pseudo code)
> 
> with (@story) do |f|
>   f.begin_form
>   f.textfield :name
>   f.end_form
> end

You already are.  Just replace "with" with "form_for" and you'll see 
that the syntax is essentially the same.

> 
> so i think the block method will save the begin_form and end_form 
> because it automatically add the begin and end before calling the block. 
> is that the main benefit?

Oh, now I see what you mean about the syntax.  Yes, that's sort of it. 
Read more about blocks in Ruby.

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] Re: Preloading database tables

2009-05-24 Thread ms

Thanks for your answer, I'll explain: I've got my migrations where I
can set up the table layout. Afterwards I want to fill this database
with some predefined records. These records should lay somewhere else
in simple text files, CSV, XML or whatever. It's just about to divide
the table definitions and the data I want to add directly after the
creation.

Thanks for your help,
ms
--~--~-~--~~~---~--~~
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: why do we use form_for @story do |f| when there is no loop?

2009-05-24 Thread SpringFlowers AutumnMoon

Andrew Timberlake wrote:
> On Sun, May 24, 2009 at 11:32 AM, SpringFlowers AutumnMoon
>  wrote:
>>
> I think it's important that you forget about the loop and focus on
> blocks, once you've understood blocks, it will no longer look like a
> loop and you'll understand that you really don't want to write it a
> different way (even though it's possible)

can i use something like:  (just pseudo code)

with (@story) do |f|
  f.begin_form
  f.textfield :name
  f.end_form
end

so i think the block method will save the begin_form and end_form 
because it automatically add the begin and end before calling the block. 
is that the main benefit?
-- 
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: Preloading database tables

2009-05-24 Thread Mk 27

Not sure what a fixture is; do you mean you want two seperate db files, 
or do you mean you want to populate the database outside of rails, and 
then use it?

-- 
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: Use of global variables...

2009-05-24 Thread Mk 27

Marnen Laibow-Koser wrote:
> Mk 27 wrote:
>> Marnen Laibow-Koser wrote:
>> 
>>> In this case, you should probably be using a local or @instance variable 
>>> in the controller.
>> 
>> *There is no way to do that in rails*.  
> 
> Well, if you're so sure of that, why are you asking for help? :)

Because, as they say, it is like pulling teeth sometimes :)

Actually, I didn't really believe that, but after doing a little more 
research, I learned that in a production environment a class variable 
will not work either, and that it is true:

*YOU CANNOT DO THAT IN RAILS*

ie, you will have to write that data to a file of some sort, and use 
some kind of per user key to identify it.  Which sucks, but I guess that 
is life.

> Do I understand correctly that you'd like to cache a database query in 
> the controller between requests?  If so, perhaps a @@class variable is 
> the way to go here.  Or maybe Rails' built-in caching would do what you 
> need.

Thanks for ringing my head Marnen re: class variables.  I only skimmed 
thru the pickaxe book on the web last week.  My stupidity.

Perhaps this issue has been solved with the "built-in caching"?  The 
aforementioned "research" was another, similar forum thread from 2006. 
Hopefully -- then I will have to admit

*YOU CAN DO THAT IN RAILS*

So thanks again -- MK


-- 
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] Preloading database tables

2009-05-24 Thread ms

Hello,

as I write a little cms system, I need to preload some table with
data. I don't know, if 'preloading' is the right name for this. I
know, that I can write into some tables right in the migration file,
but I want to have the predefined records in a seperate file, like you
have with fixtures. How do you handle this problem?

Thank you for any suggestions!
ms
--~--~-~--~~~---~--~~
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: has_many :through problem

2009-05-24 Thread Andrew Myers

Hi Manasi,

This worked.  Thank you!

Another thing I found I had to do was rename BookmarksTag.rb to 
bookmarks_tag.rb.  As a Java programmer who is just starting in ruby I 
am still coming to grips with the ruby naming conventions.

Your help was much appreciated.  Thank you again!

Andrew.

Manasi V1 wrote:
> Hi Andrew,
> 
> could you please try this -
> class Bookmark
> has_many  :bookmarks_tags
> has_many :tags, :through => :bookmarks_tags
> .
> 
> class BookmarksTag
> belongs_to :tag
> belongs_to :bookmark
> ..
> 
> Then @bookmark.tags should work.
> 
> 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] can anyone help me with showing lists with conditions?

2009-05-24 Thread Mike75

hi
i'm trying things out with rails, and I'm having trouble with showing
a list of products.
i hope someone can help me out with this..

my tables are simple and it contains the following fields

product table : id | Name | Price | Country_id
country table : id | CountryName

and I input products info with selected id numbers from the "country"
table and insert the country.id into products.Country_id.

I am trying to show countryName from the country table on the products
list.

it would be wonderful if anyone can help me out with this..

thank you
--~--~-~--~~~---~--~~
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: belongs_to not saving foreign key

2009-05-24 Thread fRAnKEnSTEin


Jeff Schoolcraft is right.  Your Author model should have this line

 :has_many :books

 In faat you should specify all the db relations in your model files,
all of them.

cheers


--~--~-~--~~~---~--~~
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: belongs_to not saving foreign key

2009-05-24 Thread Jeff Schoolcraft
your Author should :have_many :books
You also want to do something like this:

dave = Author.create(:name => 'Dave Thomas')
pickaxe = dave.books.build(:title => 'Programming Ruby 1.9')

On Sun, May 24, 2009 at 3:46 AM, Sean K  wrote:

>
> Under Rails 2.3.2 using a completely brand new project, I have 2
> models:
>
> class Author < ActiveRecord::Base
>  # name:string
> end
>
> class Book < ActiveRecord::Base
>  # title:string
>  belongs_to :author # author_id
> end
>
> And a simple test where i create a Book with an Author using the
> belongs_to and then update the foreign key directly:
>
> require 'test_helper'
>
> class BookTest < ActiveSupport::TestCase
>  test "foreign key updating" do
>a1 = Author.create! :name => 'author 1'
>b = Book.create! :title => 'rails', :author => a1
>a2 = Author.create! :name => 'author 2'
>b.update_attributes! :author_id => a2.id
>assert_equal a2.id, b.author_id  # author_id is still a1.id!
>  end
> end
>
> The test fails on the last line.   Am i doing something wrong or is
> this expected behaviour?
>
> >
>


-- 
Jeff Schoolcraft
http://thequeue.net/blog/

--~--~-~--~~~---~--~~
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: AJAX based chat plugin (beta)

2009-05-24 Thread fRAnKEnSTEin

This web based chat are not implemmented using just AJAX. thi kind of
chats uses something called "Comet", which a long-held HTTP request
allows a web server to push data to a browser, without the browser
explicitly requesting it. Now do not thing that this model is an
infinite loop to the server for refreshing data in the client(obviusly
this method will work too, but it will overload the server too much),
COMET model has a whole protocol, servers etc implemented wich can
implement this kind of comunication posible in a nice way.

You can take a look here:

http://cometdproject.dojotoolkit.org/

Just googleit you will find all about this issue.

Cheers,

Shirkavand



--~--~-~--~~~---~--~~
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: why do we use form_for @story do |f| when there is no loop?

2009-05-24 Thread Andrew Timberlake

On Sun, May 24, 2009 at 11:32 AM, SpringFlowers AutumnMoon
 wrote:
>
> we use
>
> (1..10).each do |i|
>  p i
> end
>
> so that a value is "yield" to i in a block...
>
> but what about
>
> <% form_for @story do |f| %>
>  <%= f.text_field %>
> <% end %>
>
> there is no loop at all... why do we need to make it look like a loop?
> Can't we do it without making it look like a loop?  (write in another
> way)?
>
> Also, must be use a Story instance here?  Can't we just use :story and
> achieve the same result?  The @story instance is just newly created and
> has no data at all -- does it actually help creating the form?  Can't
> :story suffice already?  thanks.

Both these examples of code use blocks, the first just happens to be a
loop, the second only looks like a loop if your first experience of
blocks is in loops.

I think it's important that you forget about the loop and focus on
blocks, once you've understood blocks, it will no longer look like a
loop and you'll understand that you really don't want to write it a
different way (even though it's possible)

Yes, you can use @story or :story and form_for will figure it out for you.
Mostly it depends on where you're using the form, new or edit etc.

Andrew Timberlake
http://ramblingsonrails.com

http://MyMvelope.com - The SIMPLE way to manage your savings

--~--~-~--~~~---~--~~
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] why do we use form_for @story do |f| when there is no loop?

2009-05-24 Thread SpringFlowers AutumnMoon

we use

(1..10).each do |i|
  p i
end

so that a value is "yield" to i in a block...

but what about

<% form_for @story do |f| %>
  <%= f.text_field %>
<% end %>

there is no loop at all... why do we need to make it look like a loop?
Can't we do it without making it look like a loop?  (write in another
way)?

Also, must be use a Story instance here?  Can't we just use :story and
achieve the same result?  The @story instance is just newly created and
has no data at all -- does it actually help creating the form?  Can't
:story suffice already?  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: AJAX based chat plugin (beta)

2009-05-24 Thread CJ

So you are firing a AJAX call on click of ENTER , right ?

Then how do you handle when you have many channels , like many rooms
in CHAT ?

I like juggernaut because it does the same without any hastle , only
issue is its FLASH based but its lovley .

Also XHRR based chat servers are cool .

On May 23, 4:10 pm, Gerda Gorter 
wrote:
> I have launched the website with a demo of the chat.
>
> the chat is still in beta please report when it goes wrong
>
> http://simple-chat.com/
> --
> 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] belongs_to not saving foreign key

2009-05-24 Thread Sean K

Under Rails 2.3.2 using a completely brand new project, I have 2
models:

class Author < ActiveRecord::Base
  # name:string
end

class Book < ActiveRecord::Base
  # title:string
  belongs_to :author # author_id
end

And a simple test where i create a Book with an Author using the
belongs_to and then update the foreign key directly:

require 'test_helper'

class BookTest < ActiveSupport::TestCase
  test "foreign key updating" do
a1 = Author.create! :name => 'author 1'
b = Book.create! :title => 'rails', :author => a1
a2 = Author.create! :name => 'author 2'
b.update_attributes! :author_id => a2.id
assert_equal a2.id, b.author_id  # author_id is still a1.id!
  end
end

The test fails on the last line.   Am i doing something wrong or is
this expected behaviour?

--~--~-~--~~~---~--~~
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: Searching/Sorting an Array of Hashes

2009-05-24 Thread timr

Your question needs a bit of clarification--please use a examples of
the query, the data set format to be searched, and the expected
result. And then repeat for the case that you are having trouble
with.

But I'll throw out some thoughts even though I am confused about what
you are trying to do...

Here is an example of how to sort_by last_name on an array of hashes
with first_name and last_name keys .
 array.sort_by{|hash| hash[:last_name]}

> irb
>> test = [{:first_name=>'tim', :last_name=>'rand'},{:first_name=>'jim', 
>> :last_name=>'band'},{:first_name=>'him', :last_name=>'crand'}]
=> [{:first_name=>"tim", :last_name=>"rand"},
{:first_name=>"jim", :last_name=>"band"},
{:first_name=>"him", :last_name=>"crand"}]
>> test
=> [{:first_name=>"tim", :last_name=>"rand"},
{:first_name=>"jim", :last_name=>"band"},
{:first_name=>"him", :last_name=>"crand"}]
>> test.sort_by{|hash| hash[:first_name]}
=> [{:first_name=>"him", :last_name=>"crand"},
{:first_name=>"jim", :last_name=>"band"},
{:first_name=>"tim", :last_name=>"rand"}]
>> test.sort_by{|hash| hash[:last_name]}
=> [{:first_name=>"jim", :last_name=>"band"},
{:first_name=>"him", :last_name=>"crand"},
{:first_name=>"tim", :last_name=>"rand"}]

To find misspelled names is a bit trickier--I would probably use the
text rubygem as it has the ability to calculate the Levenshtein
distance (basically number of substitutions, deletions and insertions)
required to spell the target using a query. You would have to compare
the query to all names and sort based on the levenshtein distance and
then pull the closest match.I have used that strategy in the past and
it works. Here is a quick demo of the syntax for the levenshtein
distance:
>irb
>> require 'text'
=> true
>> Text::Levenshtein.distance('this', 'that')
=> 2
>> Text::Levenshtein.distance('query', 'queen')
=> 2

To the extent that I think I understand your question, I bet having
some verification is going to be unavoidable. Something like the
following to catch cases when people type in a space separated first
and last name.

>> if query.match(" ")  #query is something like "first last"
>> query_first, query_last = "first last".split(/ /)[0], "first last".split(/ 
>> /)[1]
>> else
>> query_first = query_last = query
>> end

Hope that helps,
Tim


On May 23, 4:49 pm, Robert Scott 
wrote:
> I have an array of hashes that contains several fields, including
> first_name and last_name. Unfortunately, since its the result of an API
> call, I have no other ways to work with it. Regardless, I'm trying to
> build a basic search function where a user can enter a name and it will
> display the results from a newly created array.
>
> I'm guessing that sort_by will be the best route to go, but I've been
> unsuccessful in finding out how to use it with multiple fields. Any
> guesses?
>
> The second part to the question is how you structure the sort_by, if
> that is the best way, to find objects that are similar to the requested
> query. It's not so much that a user would mispell a name (although that
> would be helpful) but if they put in a firstname + lastname pair, it
> wouldn't technically match with either field on its own.
>
> Thanks in advance. :)
> --
> 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] How to integrate Google adsense?

2009-05-24 Thread Great Kindness

I was surprised to see not much on the web about integrating Google
AdSense into Rails apps. I found this post:

http://atservice.blogspot.com/2008/07/google-ad-sense-code-implementation.html

but the meat of that post is a link to a file that doesn't exist any
more. Can anyone direct me to something useful that's already
published?

--~--~-~--~~~---~--~~
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 to pass arguments to functions in callbacks in model ?

2009-05-24 Thread Arpit Jain
I need to pass attributes to the function called in callback in rails
model.  For example,

after_save :update_something
after_destroy :update_something, true  #true is the argument that I need to
pass

private
def update_something(value = false)
  #...
end


I found a way to do it like this

after_save :update_something
after_destroy {|record| record.update_something(true)}

But in this case, I need to make the function update_something public, which
I don't want to do.

Any help ?


-- 
Arpit Jain

--~--~-~--~~~---~--~~
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] protect_from_forgery issue

2009-05-24 Thread phil

Hi,
I just redeployed my app for a very minor source code change and now I
am getting these errors:
No :secret given to the #protect_from_forgery call

for a page that has a remote_form_for on it.

1) Why would this change? The offender seems to usually be Googlebot,
but not always. I've been always getting lots of google bot hits, so
what has changed now.
2) Why only on this one page? I actually include the partial that
contains the code it is complaining about on almost every page
3) What can I do to fix it?

For me the weird thing is that it is not giving me the error when
googlebot tries to call the remote form, but actually it seems to be
happening when it is trying to render it!

Should I be using a secret

I am running rails 2.1.2 (via ec2onrails).

Help! Our hoptoad is reporting 150 of these since yesterday!
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---