In Ruby on Rails routing (using route.rb), can it say, for any URL
having the form:
www.example.com/ ... #! ...
then use controller `redirect` ?
This is so that in AJAX, some page can tag the `#!` at the end of URL so
that the real content of interest is the part after the `#!`
--
Posted v
I thought it could be created in a few steps but it can't yet:
rails poly
cd poly
ruby script/generate scaffold animal name:string obj_type:string
obj_id:integer
rake:migrate
ruby script/generate scaffold human name:string
passportNumber:string
rake:migrate
ruby scr
In Ruby on Rails, routes.rb, if we create a "named route"
map.something ":a/:b", :controller => 'foobar'
it will also create "something_path" and "something_url" which are two
methods usable in the controller and in the view. Does "map.connect"
create something like that too? Otherwise, isn'
In Ruby on Rails, if a partial (such as _msgbox.html.erb) need to use
Javascript by
javascript_include_tag :defaults
but then, the page layout or other view may also have that same line, so
the same javascript files will be included multiple time?
Is there a way to tell Rails just to include
The following is an error for using RoR with MySQL:
C:\ror\shov17>rake db:migrate
(in C:/ror/shov17)
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please
install
the mysql gem and try again: gem install mysql.
rake aborted!
193: %1 is not a valid Win32 application. -
c:/ruby/
Marnen Laibow-Koser wrote:
>
> Or...hmm. Check out CoffeeScript; it's a bit like Haml for JS.
if only there is a Ruby to JS converter.
--
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
Marnen Laibow-Koser wrote:
> Jian Lin wrote:
>> Marnen Laibow-Koser wrote:
>>
>>>> JS Minifier when there are 5 lines of code?
>>>
>>> If there are only 5 lines of code, why do you need private comments in
>>> the first place?
>>
&g
Marnen Laibow-Koser wrote:
>> JS Minifier when there are 5 lines of code?
>
> If there are only 5 lines of code, why do you need private comments in
> the first place?
Do you often see other people's way of doing things needing to abide to
your rule book? Such as: if there are only n lines of
Marnen Laibow-Koser wrote:
>> 1) -# to add comment but not to show it to the public
>
> Use a JS minifier.
>
>> 2) using if else to output something based on some condition
>> 3) using loop
>
> Use JavaScript control structures for these, not Ruby control
> structures.
>
>> 4) providing value
Is it feasible that when running unit test or functional test, when it
detects that the "test" db is the same as the development db, then give
a warning: are you sure? the whole db will be wiped cleaned - Yes/No.
Because some people who are new to Rails and even experienced people may
make a simp
Marnen Laibow-Koser wrote:
>> foo.js?1273424325
>>
>> which is to use the cached version as long as there is no code change,
>> but recompile it when there is code change?
>
> Because it's a different kind of caching. JavaScript caching simply
> involves using the browser cache for included f
Marnen Laibow-Koser wrote:
>
> If you think you need Ruby in your JS, you've got a design problem. Fix
> it.
i can think of a few cases where Ruby might be wanted inside of
Javascript output:
1) -# to add comment but not to show it to the public
2) using if else to output something based on s
At work, we have a situation where when
script/server
is run, then all the controller code is cached. This is to speed up the
development server. But that will mean that whenever we change the
controller code, we need to restart the server.
So we can turn off the caching of controller code a
Jian Lin wrote:
> but it seems the only thing allowed is
>
> :javascript
> $('#aDiv').html('#{a_ruby_variable}';
correction: (missing the ending paren)
:javascript
$('#aDiv').html('#{a_ruby_variable}');
--
Posted via http:/
It seems that inside of HAML's :javascript filter, no Ruby code is
allowed, not even a comment.
So this is NOT allowed:
:javascript
- 1.upto(10) do |i|
:javascript
-# just a comment not to show to public
(somebody said there is not way to hide comment like that inside a
:javascript filter.
If a cookie has several items, and is encoded as JSON text as the value
of the cookie, the order is actually apparent in the cookie's text
But if JSON.decode is used:
ActiveSupport::JSON.decode(cookies['item_list'])
and the result is actually in a hash, then the ordering is lost...
Is it true
RJS is very good for sending Javascript code back to the browser saying
"Your AJAX is successful and by the way you can update the UI to signal
to the user using the following Javascript I am going to send you."
How about other webpage interactivities, dynamic HTML, is RJS suited for
doing that as
I was going to change the background of a div from white to red and then
from red back to white, so this is used in an RJS file:
page[:vote_score].visual_effect :highlight, :startcolor => '#ff',
:endcolor => '#ff'
page[:vote_score].visual_effect :highlight, :startcolor => '#ff',
:
So it looks like on RoR, when Ajax (using form_remote_tag) returns a
success code, Javascript is also returned to handle the visual effects.
using Fiddler, I do see the following response:
try {
Element.update("vote_score", "Score 58");
$("vote_score").visualEffect("highlight");
}
In some book, it is recommended that to_param is changed to
class Story < ActiveRecord::Base
def to_param
"#{id}-#{name.gsub(/\W/, '-').downcase}"
end
end
so that the URL is
http://www.mysite.com/stories/1-css-technique-blog
instead of
http://www.mysite.co
Rick Denatale wrote:
> That's actually not the whole story, and excerpt from the output of
> gem help install:
>
> Description:
> The install command installs local or remote gem into a gem
> repository.
>
> For gems with executables ruby installs a wrapper file into the
> executable
Frederick Cheung wrote:
> On May 23, 7:10�am, Jian Lin wrote:
>
>>
>> So clearly, s.votes is an empty Array object.
>>
>
> Actually it's not. It's an AssociationProxy object pretending to be an
> instance of Array
>
> Fred
not like this?
In Ruby on Rails, say a Story object can "has_many" Vote objects (a
story is voted "hot" by many users).
So when we do a
s = Story.find(:first)
"s" is a Story object, and say
s.votes
returns "[]"
and
s.votes.class
returns "Array"
So clearly, s.votes is an empty Array object.
A
pepe wrote:
> Just in case it applies here is an extract from the Pickaxe book
> (Second edition, page 217):
>
> "Threre's a subtlety when it comes to installing different versions of
> the same application with RubyGems. Even though RubyGems keeps
> separate versions of the application's library
On a Mac running Snow Leopard, the Rails version was 2.3.5 (by using
rails -v)
and then I used gem install to install about 20 things, and maybe there
was a line on the instructions that was there in the past that says
gem install rails -v=1.3.5
and I ran it anyways, thinking that maybe 1.3.5
Jian Lin wrote:
> yes, column_names gave a better order:
>
> C:\Software Projects\ror\shov10>ruby script/console
> Loading development environment (Rails 2.3.5)
>>> Story.column_names
> => ["id", "name", "link", "created_at&
Philip Hallstrom wrote:
>> also, the use of i[0], i[1] seems a little less structured than if
>> i.attr_name, i.attr_value can be used.
>
> look into "s.attributes.each_pair |k,v|"
>
>
>> the row == 1 situation also seems like somewhat not adhering to DRY.
>
> You could consider using Story.c
Philip Hallstrom wrote:
>><%= "#{h i}\n" %>
>> <% end %>
>> <%= "\n" %>
>> <% end %>
>
> @stories.attributes
>
> http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002348
>
> -philip
Great thanks.
So I have come up something like this:
the row == 1 check is to print the head
to wrap each instance variable of an ActiveRecord object between ""
and "", is there a way to "loop through" them, at least in the
debug mode, no matter there is getter methods to get them or not, or at
least the ones with the getter methods?
Such as
<% @stories.each do |s| %>
<%= "" %>
<% s.
Jian Lin wrote:
> using join looks like will create only n + 1 string objects...
>
ah, on second thought, doesn't the join() method actually will create n
string objects too? (the next one longer than a previous one), so it
would be creating 2n string objects too.
--
Post
Philip Hallstrom wrote:
> In the above case you could do this...
>
> <%= @stories.map {|s| content_tag(:div, h(s.inspect)) }.join %>
i was at first worried that if the print out is long, like a few hundred
lines, then it can create many string objects.
using join looks like will create only n
In the view code, say it is
<% @stories.each do |s| %>
<%= "#{h s.inspect}" %>
<% end %>
it would be breaking the code into 3 <% %> and <%= %>
is there a way to just have one <% %> or <%= %> so as to keep the code
more flowing together?
--
Posted via http://www.ruby-forum.com/.
--
You r
Jette Chan wrote:
> OK. Now I know...
> I thought t you can see "1 gem installed"
> So, it means you've already finished install mysql gem now.
> And the following errors come from when installation the documentation.
>
> Actually you already can use this gem now.
but when i use
http://localhost
Jette Chan wrote:
> Yes, gem install mysql is needed.
> But, I'm not sure what do you mean lots of errors.
> Maybe you should post your errors here.
sure, a sample run is:
C:\Software Projects\ror\shov6>gem install mysql
Successfully installed mysql-2.8.1-x86-mingw32
1 gem installed
Installing ri
I set up Rails from scratch using the methods on:
http://rubyonrails.org/download
and also:
gem install sqlite3-ruby
download sqlite3.dll into c:\ruby\bin
change config/database.yml adapter lines for dev, test, prod all to
sqlite3
so sqlite3 can be used now...
but what if i also installed MySQ
Jonathan Rochkind wrote:
> Jian Lin wrote:
>> I wonder if a Ruby on Rails developer has encounter this before: suppose
>> it is a long article (say 100,000 words), and I need to write a Ruby
>> file to display page 1, 2, or page 38 of the article, by
>>
>> displa
I wonder if a Ruby on Rails developer has encounter this before: suppose
it is a long article (say 100,000 words), and I need to write a Ruby
file to display page 1, 2, or page 38 of the article, by
display.html.erb?page=38
but the number of words for each page can change over time (for example,
pepe wrote:
> I've run into the same problem several times before and never thought
> too much of it, just made the correct change to be able to compile and
> kept going. Now that I think about it I might have an answer.
>
> The ruby code is just what it is between <% and %>. Those 'delimiters'
>
hm... you know what, my coworker had this one line:
and the page would still validate perfectly as XHTML, but IE will render
it differently from FF.
FF will take it as a closing div. IE will not take it as a closing div.
so I will have perfectly validated code that behaves differently on tw
Lee Smith wrote:
> Trying to change the way Rails lays down a stylesheet include is
> really a waste of time. This HTML vs XHTML syntax only matters if
> you're validating...otherwise, the browser renders it as HTML.
>
> Don't waste your time and definitely update your browser.
i think there ar
Salil Gaikwad wrote:
> I Commented code in erb in following ways
>
> <%# This is Comment %>
>
> <%#
> This is Comment
> %>
>
> <%#= This is Comment %>
>
> <%#=
> This is Comment
> %>
i see. that's smart. then we don't need <%= #comment %> to work. but
if it can, i think it might be go
i think PHP doesn't have such simple functions yet... does Ruby have
it?
if in PHP, when we add a param to the URL
$redirectURL = $printPageURL . "?mode=1";
it works if $printPageURL is "http://www.somesite.com/print.php";, but if
$printPageURL is changed in the global file to
"http://www.some
I wonder if we usually use Iconv to translate to various encoding?
For example:
Iconv.conv("UTF-8", "BIG-5", content)
or
Iconv.conv("UTF-8", "CP950", content)
or do we usually use other packages? One reason is that BIG-5 can
cause an exception while CP950 won't on some content, and both of
Michael Schuerig wrote:
> On Sunday 10 May 2009, Jian Lin wrote:
>> so how to do inserts in bulk? by using
>>
>> Phrase.connection.execute("insert into phrases(s,frequency,length)
>> values('#{phrase}',#{frequencies[phrase]},#{lengths[phrase]})")
Frederick Cheung wrote:
> On May 10, 10:41�am, Jian Lin
> wrote:
>> it actually force write to the physical disc?
> It's never that simple (and yes under the appropriate circumstances
> the drive is supposed to flush to the actual disk). For example
> there's a c
Jian Lin wrote:
> Save and destroy are automatically wrapped in a transaction
>
> so i think create is also invoking a save...
i just read from Learning Rails the book (p.50 if remembered correctly)
that
create is 3 operations in one: it has a new, an assignment of values,
and a
Gary Doades wrote:
> Aha It looks like ActiveRecord has an enormous overhead in
> creating/saving records.
>
> If you change the inserts to this
>
> puts Benchmark.measure {
> Phrase.transaction do
>all_phrases.each do |phrase|
> Phrase.connection.execute("insert into phrases(s
Gary Doades wrote:
>
> "Starting inserting records"
> 31.996000 0.639000 32.635000 ( 35.356000)
> 3
>
> For 3 inserts with all indexes:
>
> "Starting inserting records"
> 32.795000 0.982000 33.777000 ( 37.103000)
> 3
>
> I Don't know if it is the hash lookup code or Active
Gary Doades wrote:
> Jian Lin wrote:
>> ok, the following code with 6000 records insert will take 13.3 seconds
>> to finish (just for the db portion). if i change 6000 to 3 then it
>> will take 67 seconds.
>>
>
> OK, I created the table and the index and
ok, the following code with 6000 records insert will take 13.3 seconds
to finish (just for the db portion). if i change 6000 to 3 then it
will take 67 seconds.
it is being run using
ruby script/runner foo.rb
code:
srand(123)
Gary Doades wrote:
> Jian Lin wrote:
>>
>> but it is still the same: it took 75 seconds...
>
> That's because it's still really the same code!
>
>> i wanted the length, which is the count of word because in the future i
>> might want to do query
Michael Schuerig wrote:
> On Sunday 10 May 2009, Jian Lin wrote:
>> end
> Consider
>
> Phrase.transaction do
> frequencies.each do |phrase, freq|
> Phrase.create!(:s => phrase, :frequency => freq)
> end
> end
>
> Hash#each passes keys and v
Gary Doades wrote:
>
> I'm not sure how you get 34000 records from 6000 words. Surely you
> should get less not more.
>
>> it would run for at least a minute... that's kind of weird...
>>
>
> Are you sure it is just the above code that is taking a minute and not
> the bit of code that counts
Jian Lin wrote:
> i was doing it like this:
>
>
> all_phrases = frequencies.keys
> Phrase.transaction do
> all_phrases.each do |phrase|
> recordPhrase = Phrase.new(:s => phrase, :frequency =>
> frequencies[phrase], :length => lengths[phrase])
> rec
Gary Doades wrote:
> If you have made the change to count up words first and then *insert*
> all the (word,count) records into the database in a *single* transaction
> then it ought to take less than a second. I would expect that the total
> number of (word,count) records is in the order or hundr
Colin Law wrote:
> Have you made the suggested change to count the words in the document
> first
> then update the db, so that you are not updating each record in the
> database
> many times (presumably hundreds of times for common words)? This will
> change the number of db accesses from the t
Phlip wrote:
> Jian Lin wrote:
>
>> so i re-ran the test and it worked quite quickly... down to 1 minute or
>> so instead of 30 minutes... (for several pages)... and the db size is
>> only 2.5MB (i created another rails project to start anew). So
>> if we are j
Gary Doades wrote:
> Jian Lin wrote:
>> in RAM as much as possible?
> The database can be cached in ram by most database engines. However,
> most database engines will also make sure that every transaction
> (insert, update, delete) is committed to disk by forcing a write to t
great... will try it out now.
actually, i was thinking, that the computer sometimes has 1GB free RAM
or 3GB free RAM (of the 4GB of RAM). how come the OS doesn't
automatically create a cache for the 45MB db file? If the OS creates
the cache, everything happens in memory, and it should be qui
Colin Law wrote:
> Is this a test or a real requirement? If it is a real requirement then
> count the words in memory first and then update the db so each record is
> only written once.
>
> Colin
>
> 2009/5/9 Jian Lin
it is a real requirement... so how do i update t
Colin Law wrote:
> Would not the index make the lookup faster but the write slower? Is it
> that
> the cacheing would mean that the lookup would be pretty quick anyway,
> even
> without an index?
>
> Colin
>
> 2009/5/9 Gary Doades
yeah, seems like the search will be a lot faster with the i
Gary Doades wrote:
> I'm glad you said it was a test because it wouldn't be nice to do that
> for real.
>
> It looks like you've got at least 12000 transactions in there (select +
> update). Any indexes would make it worse.
>
> I'm guessing that this would take around 5 minutes on decent single
is it true that surveymonkey.com won't show the survey answers to
general users who voted? (unless the survey creator is not using a
basic account)...
so the result so far is:
Mac: 10
Linux:9
Windows: 4
Other:1
--
Posted via http://www.ruby-forum.com/.
--~--~-~--~~
i am writing a test program for ActiveRecord, and it reads a document
which is like 6000 words long. And then i just tally up the words by
recordWord = Word.find_by_s(word);
if (recordWord.nil?)
recordWord = Word.new
recordWord.s = word
end
if recordWord.count.nil?
I want to put the processing logic in the controller... and it has a
strip_tags call... and the controller portion will say the function
doesn't exist.
so is there a way to call strip_tags from the controller? (instead of
from view).
--
Posted via http://www.ruby-forum.com/.
--~--~-~-
Alberto Santini wrote:
> Jian Lin wrote:
>> actually... sometimes i want to output multiple things inside of <% %>,
>> or put everything inside a loop and inside a <% %>, so that's why the
>> question of <% puts 123 %>
>
> I think yo
by the way, i was using Notepad++ a lot on the PC, and almost want to
just use that for anything... but it seems to have no way to open up a
folder like TextMate does... so it is a bit inconvenient for RoR
development.
--
Posted via http://www.ruby-forum.com/.
--~--~-~--~~---
Rob Lacey wrote:
> <%= "blah" %>
>
> is what you are looking for
actually... sometimes i want to output multiple things inside of <% %>,
or put everything inside a loop and inside a <% %>, so that's why the
question of <% puts 123 %>
--
Posted via http://www.ruby-forum.com/.
--~--~--
Conrad Taylor wrote:
>
> Jian, I use Xcode sometimes when I'm doing MacRuby development with
> Monaco font and a size of 14pt. Xcode allows you to change the font
> size as
> do most applications that allow you enter text.
so there is no need to spend 39 euro to buy TextMate? I was wondering
Jian Lin wrote:
> it seems that <% %> is not exactly the same as in which,
>
>
> PHP's
>
>
> will add to the output
>
> but
>
> ERB's
> <% puts "something" %>
>
> will not?
actually, i found that <% puts 123 %
does somebody use XCode on Mac for RoR instead of TextMate? I wonder
how is it compared to TextMate... TextMate uses the default font of
Monaco... the Xcode screenshot on Wikipedia uses Courier... I wonder if
Xcode looks as good as TextMate when the font is changed to Monaco as
well? Thank you
I wonder if most of the people using RoR is using it on Mac? How about
we make a tally here... we can enter our platform here and see what
other engineers are using:
http://www.surveymonkey.com/s.aspx?sm=Xjv89bNS9fvJGoi_2bnsNimg_3d_3d
thanks.
--
Posted via http://www.ruby-forum.com/.
--~--~-
it seems that <% %> is not exactly the same as in which,
PHP's
will add to the output
but
ERB's
<% puts "something" %>
will not?
Does someone know if JSP and ASP behave like ERB or PHP and can make a
summary of their likes and differences? Thank you.
--
Posted via http://www.ruby-foru
73 matches
Mail list logo