Thursday, March 18, 2010

[Rails] Re: render a Google Chart to a file

Use following method to get image in file from any url


Net::HTTP.start("#{DOMAIN_URL}") { |http|
resp = http.get(PARAMS)
open( "#{OUTPUT_DIR}/#{file_name}.png", 'wb' ) { |file|
file.write(resp.body)
}
}

Where DOMAIN_URL: http://chart.apis.google.com
PARAMS:
/chart?cht=bvg&chbh=a&chd=s:vttusty&chs=500x300&chxt=x,y&chxl=0:|Sun|Mon|Tue|Wed|Thu|Fri|Sat|1:|0|2|4|6|8|10|12


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

[Rails] migration

Hi all,

I have migrated with some tables in my application. After some days i
need to add few more tables to database. The initial tables in database
have some data. when i try to migrate the database for second time with
rake db:migrate it is saying the alredy table exist <table name> and
rake is aborted. i dont want to loose the old data and i want to add new
tables to alredy exiested database

how to do this. Please help me.


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

[Rails] Will paginate display

Hi friends i am using will_paginate plugin for pagination
Im having more records in my database im listing 10 records per page
know my pagination link was look like this
<< Previous    1 2 3 4 5 6 7 8 9 266    Next >>

But i would  like to display the pagination links look like this

<< Previous    1 2 3 4 5 6 7 8 9 10    Next >>

any idea how to implement this please help me to implement this

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

[Rails] Re: RJS error: TypeError: element is null

> I believe this is expecting to find a div with id chat_area to
> replace. I do not see this div in the code below, though I may be
> just not be seeing it.
>
> Colin
Following div is present on my index.rhtml

<div id="chat_area">
<%= render :partial=>'chat_area' %>
</div>


I don't know what is the problem with this div or partial's content
while using same technique i am updating my other div's

Regards,

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

[Rails] Rails, 1.9 & Encoding - does it work?

Hey all,

I've been looking into moving our Rails app to 1.9 and am having lots of
trouble with string encodings, especially when it comes to file uploads.

We allow users to upload text files, which may, or may not, have
accented characters in them. If there are accented characters, we insist
that the file is UTF-8, but if there are no accented characters we don't
care what encoding the file is.

It seems that w/ Rails 2.3.5 ALL files upload as ASCII-8BIT, regardless
of OS $LANG setting, or actual file encoding.
params[:file].external_encoding also appears to be ASCII-8BIT as well,
so I can't use content.encode("utf-8", xxx) because I've no idea what
the file is *supposed* to be encoded as.

Since I'm on OSX and $LANG == en_AU.UTF-8, shouldn't all files default
to UTF-8 unless explicitly told otherwise?

Has anyone got 2.3.5 working well w/ 1.9 when accented characters are
involved?

Any tips?

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

[Rails] Re: Records created while tests are running are not being saved.

Just for records. Line #47 -
http://code.google.com/p/kopal/source/browse/test/network/connect_controller_test.rb?r=876e7c80c420e5faca9492bd50ed1dd943cb90ac

On Mar 18, 3:08 pm, Vikrant Chaudhary <nas...@gmail.com> wrote:
> In following code -
>
> require "test_helper"
> Class SomeControllerTest < ActionController::TestCase
>
>   def test_something
>     record = SomeModel.create :name => 'test'
>     record.save!
>     gets
>   end
>
> end
>
> Above record is not being saved in the database. I can confirm this by
> pausing execution by calling gets() and doing a "SELECT * FROM
> some_models" right into the test database which returns no rows.

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

[Rails] getting data from a through table

im using has_many through and the through table has some data i want
but i cant seem to access it using straight rails

<code>
class AttributeObjects < ActiveRecord::Base
belongs_to :attributes
belongs_to :objects
end

class Attributes < ActiveRecord::Base
has_many :attribute_objects
has_many :objects, :through => :attribute_objects
end

class Objects < ActiveRecord::Base
has_many :attribute_objects
has_many :attributes, :through => :attribute_objects
end

</code>

now imagine that attribute_objects also contains a rating
so when i say, object.attributes, id like to get the rating too
that doesnt seem to be possible with the has_many relationship
if i could force the join on the object attributes to bring the
attribute_objects fields also...maybe

i think i have to write custom sql for this

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

[Rails] Current CentOS-Nginx-Passenger script?

I've got bits and pieces of old install scripts but the versions are
far out of wack!
Anyone recently view or use an install script for all these goodies?
Many thanks,
David

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

[Rails] Re: render a Google Chart to a file

On Mar 18, 9:00 pm, Adam Ziemba <li...@ruby-forum.com> wrote:
> Colin Law wrote:
> >     open("http://chart.apis.google.com/chart#{CGI.escape('?cht=bvg&chbh=a&chd=s:vttusty&chs=500x300&chxt=x,y&chxl=0:|Sun |Mon|Tue|Wed|Thu|Fri|Sat|1:|0|2|4|6|8|10|12')}")
> > do |chart|
> >       File.open('chart.png', 'w') {|f| f.write chart.read }
> >     end
>
> I definitely understand the why you would want to escape the URI, but
> I'm not convinced that this approach will never work.
>
> The URL with the escaped characters causes Google to reject it as
> invalid parameters, which is why you got all that HTML and Javascript.
> E.g. if you use your browser to open the result of the above URI with
> escaped characters:
>
> http://chart.apis.google.com/chart%3Fcht%3Dbvg%26chbh%3Da%26chd%3Ds%3...
>
> You are redirected to the Google chart API. Retaining the original
> characters with:
>
> http://chart.apis.google.com/chart?cht=bvg&chbh=a&chd=s:vttusty&chs=5...Sun|Mon|Tue|Wed|Thu|Fri|Sat|1:|0|2|4|6|8|10|12
>
> you'll get a PNG image and nothing else.
>
> Okay, so Google doesn't want the escaped characters, and the URI::open
> method doesn't want the plain characters... or does it? Is there no way
> around this? The thing is the characters used in the URL above are
> valid, or so I thought. I pass these kind of characters as parameters
> from controller to view all throughout my application, with full browser
> compatibility.
>
> I tried using backslashes for all the characters, e.g. "\&" instead of
> "&" and the URI open method still rejects it.
>
> I've seen some people successfully get images to save to the file system
> using URI, but I'm assuming all their code is outdated as I could not
> get it to work. Also, the image URL they were using actually pointed to
> a PNG image, with a PNG extension, whereas the Google Chart URL will
> return a PNG image.
>
> I appreciate all the help!
> --
> Posted viahttp://www.ruby-forum.com/.

Seems an inadequacy of Ruby URI library. Curb (Ruby libcurl bindings)
works simply and easily though:

ruby-1.9.1-p376 > require 'open-uri'
=> true
ruby-1.9.1-p376 > png = "http://chart.apis.google.com/chart?
cht=bvg&chbh=a&chd=s:vttusty&chs=500x300&chxt=x,y&chxl=0:|Sun|Mon|Tue|
Wed|Thu|Fri|Sat|1:|0|2|4|6|8|10|12
"
=> "http://chart.apis.google.com/chart?
cht=bvg&chbh=a&chd=s:vttusty&chs=500x300&chxt=x,y&chxl=0:|Sun|Mon|Tue|
Wed|Thu|Fri|Sat|1:|0|2|4|6|8|10|12
"
ruby-1.9.1-p376 > open png
URI::InvalidURIError: bad URI(is not URI?):
http://chart.apis.google.com/chart?cht=bvg&chbh=a&chd=s:vttusty&chs=500x300&chxt=x,y&chxl=0:|Sun|Mon|Tue|Wed|Thu|Fri|Sat|1:|0|2|4|6|8|10|12
from /home/xeno/.rvm/ruby-1.9.1-p376/lib/ruby/1.9.1/uri/
common.rb:156:in `split'
from /home/xeno/.rvm/ruby-1.9.1-p376/lib/ruby/1.9.1/uri/
common.rb:174:in `parse'
from /home/xeno/.rvm/ruby-1.9.1-p376/lib/ruby/1.9.1/uri/
common.rb:626:in `parse'
from /home/xeno/.rvm/ruby-1.9.1-p376/lib/ruby/1.9.1/open-
uri.rb:32:in `open'
from (irb):3
from /home/xeno/.rvm/ruby-1.9.1-p376/bin/irb:15:in `<main>'
ruby-1.9.1-p376 > require 'curb'
=> true
ruby-1.9.1-p376 > c = Curl::Easy.perform png
=> #<Curl::Easy http://chart.apis.google.com/chart?cht=bvg&chbh=a>
ruby-1.9.1-p376 > File.open("png.png", "w") {|f| f.write c.body_str}
=> 5445
ruby-1.9.1-p376 >

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

[Rails] Re: Symbol as array index error ?

On Mar 18, 8:07 pm, Frederick Cheung <frederick.che...@gmail.com>
wrote:
> On Mar 19, 12:37 am, Dudebot <craign...@gmail.com> wrote:> Sorry for being so dense, but why does
>
> > @monkey.delete_if{ |k,v| v[ "value" ] == '' }
>
> > Throw the same error?  Any idea what the proper syntax would be to
> > delete the element for which value is blank?
>
> Shouldn't do - apart from anything else you're not using any symbols
> in this one, and it seems to work ok on my machine.

I haven't been able to get a strategy which deletes, but have been
able to get a building strategy:

@purple = {}
@monkey.each { |k,v| @purple[ k ] = v if !v[ :value ].blank? }

which works.

Any ideas how to get syntax working which deletes instead of builds..
because I'm obsessive compulsive :)

TIA,
Craig

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

[Rails] Re: Symbol as array index error ?

On Mar 19, 12:37 am, Dudebot <craign...@gmail.com> wrote:
> Sorry for being so dense, but why does
>
> @monkey.delete_if{ |k,v| v[ "value" ] == '' }
>
> Throw the same error?  Any idea what the proper syntax would be to
> delete the element for which value is blank?
>
Shouldn't do - apart from anything else you're not using any symbols
in this one, and it seems to work ok on my machine.

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

[Rails] Re: Re: render a Google Chart to a file

Colin Law wrote:

> open("http://chart.apis.google.com/chart#{CGI.escape('?cht=bvg&chbh=a&chd=s:vttusty&chs=500x300&chxt=x,y&chxl=0:|Sun|Mon|Tue|Wed|Thu|Fri|Sat|1:|0|2|4|6|8|10|12')}")
> do |chart|
> File.open('chart.png', 'w') {|f| f.write chart.read }
> end

I definitely understand the why you would want to escape the URI, but
I'm not convinced that this approach will never work.

The URL with the escaped characters causes Google to reject it as
invalid parameters, which is why you got all that HTML and Javascript.
E.g. if you use your browser to open the result of the above URI with
escaped characters:

http://chart.apis.google.com/chart%3Fcht%3Dbvg%26chbh%3Da%26chd%3Ds%3Avttusty%26chs%3D500x300%26chxt%3Dx%2Cy%26chxl%3D0%3A%7CSun%7CMon%7CTue%7CWed%7CThu%7CFri%7CSat%7C1%3A%7C0%7C2%7C4%7C6%7C8%7C10%7C12

You are redirected to the Google chart API. Retaining the original
characters with:

http://chart.apis.google.com/chart?cht=bvg&chbh=a&chd=s:vttusty&chs=500x300&chxt=x,y&chxl=0:|Sun|Mon|Tue|Wed|Thu|Fri|Sat|1:|0|2|4|6|8|10|12

you'll get a PNG image and nothing else.


Okay, so Google doesn't want the escaped characters, and the URI::open
method doesn't want the plain characters... or does it? Is there no way
around this? The thing is the characters used in the URL above are
valid, or so I thought. I pass these kind of characters as parameters
from controller to view all throughout my application, with full browser
compatibility.

I tried using backslashes for all the characters, e.g. "\&" instead of
"&" and the URI open method still rejects it.

I've seen some people successfully get images to save to the file system
using URI, but I'm assuming all their code is outdated as I could not
get it to work. Also, the image URL they were using actually pointed to
a PNG image, with a PNG extension, whereas the Google Chart URL will
return a PNG image.


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

[Rails] Re: Symbol as array index error ?

On Mar 18, 4:59 pm, Frederick Cheung <frederick.che...@gmail.com>
wrote:

> Because @monkey is a hash what gets yielded to you is an array, the
> first element is the key (ie '133' or '145') and the second is the
> value, whereas your code seems to assume that x is a hash.

Sorry for being so dense, but why does

@monkey.delete_if{ |k,v| v[ "value" ] == '' }

Throw the same error? Any idea what the proper syntax would be to
delete the element for which value is blank?

TIA,
Craig

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

[Rails] Re: Rails + Mysql

On Mar 18, 12:36 am, Conrad Taylor <conra...@gmail.com> wrote:
> José, can you verify that MySQL is running by doing the following:
>
> $ mysql -u<username>

Yes it's running...

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

[Rails] Can't get gems to work

I tried deleting the gem cache and updating gems but I get the following
error:

[computer1][/]$ gem update --system
Upgrading RubyGems...
Attempting remote upgrade of rubygems-update
Attempting remote installation of 'rubygems-update'
Successfully installed rubygems-update-1.3.6
Installing RDoc documentation for rubygems-update-1.3.6...
Could not find main page README
Could not find main page README
Could not find main page README
Could not find main page README
Updating version of RubyGems to 1.3.6
Installing RubyGems 1.3.6
./lib/rubygems.rb:124: uninitialized constant Gem::RbConfig (NameError)
from setup.rb:24
RubyGems system software updated

I am thinking this might have something to do with the fact that I can't
get gems to install anything withoug getting the error:

ERROR: While executing gem ... (Gem::GemNotFoundException)
Could not find paperclip (> 0) in the repository


Can anyone help me get this working, I'm at a complete standstill with
developement?

thanks

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

[Rails] Rail Quickstart Guide: Always receiving "template missing" errors.

Hello,

Upon going through the rails quickstart guide:
http://guides.rubyonrails.org/getting_started.html & also this guide
here: http://fuelyourcoding.com/creating-your-first-ruby-on-rails-application-from-scratch/
- I always get "Missing Template" errors.

Specifically:
"Template is missing
Missing template posts/index.erb in view path app/views"

Currently the file index.html.erb lives in app/views/posts/ - why is
the error message looking for a .erb file when there is a .html.erb
file in the folder that was created by a scaffold command? Renaming
the file to .erb does not solve the problem.

Here's my setup info from localhost:3000
Ruby version 1.8.7 (universal-darwin10.0)
RubyGems version 1.3.6
Rack version 1.0
Rails version 2.3.5
Active Record version 2.3.5
Active Resource version 2.3.5
Action Mailer version 2.3.5
Active Support version 2.3.5
Application root /Users/vtgbeats/[ Projects ]/[ Rails Apps ]/slambook
Environment development
Database adapter sqlite3
Database schema version 20100318235949

The routes.rb file is in default state.

I've successfully created small RORs apps before and now I can't even
render a view, please help. Thanks everyone,
Stone

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

[Rails] Re: undefined method error despite the fact it doesn't exist

Hi John,
I would check your source code in app/views/resources/index.html.haml
(or a view helper for that view) for a typo since it's looking for a
method named something similar to what you have (e.g change
"render_index_row_action_pprove" to "render_index_row_action_approve")

HTH

On Mar 18, 7:43 pm, John Merlino <li...@ruby-forum.com> wrote:
> Hey all,
>
> I'm getting a strange, unexplainable error. It returns undefined method
> `render_index_row_action_pprove'. I performed a search on my entire
> application and no such method exists. There is a
> render_index_row_action_approve but not a
> render_index_row_action_pprove.
>
> NoMethodError in Student_requests#index
>
> Showing app/views/resources/index.html.haml where line #20 raised:
>
> undefined method `render_index_row_action_pprove' for
> #<ActionView::Base:0x105b3a780>
>
> Extracted source (around line #20):
>
> 17:           = render_index_row_index index
> 18:           - resources_index_row(rsrc).each do |row|
> 19:             = row
> 20:           = render_index_row_actions(rsrc,
> resources_index_row_actions(rsrc), options)
> 21:   - options[:with_limit_selector] = false
> 22:   = render_index_bottom_pagination_bar options
>
> Is this a rails glitch, perhaps it is reading the method name wrong? Is
> there anyway to fix this?
> Thanks for any response.
> --
> 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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.