Posts Tagged ror

hide_action


If for some reason you must make a method in a controller public but don’t want it to be accessible as an action,
hide it using hide_action.

Code:

class OrderController < ApplicationController
    def create_order
        order = Order.new(params[:order])
            if check_credit(order)
               order.save
            else
              # …
           end
    end
   
   hide_action :check_credit
   
    def check_credit(order)
       # …
    end
end

, , ,

Add comment November 4, 2008

“Proc.new vs Lambda in Ruby”

I found the following lines of code on Wikipedia today. It’s a very succinct description of one important difference between a lambda and a Proc. Try printing the return value of f.call for more insight.


def foo
f = Proc.new { return “return from foo from inside proc” }
f.call # control leaves foo here
return “return from foo”

end

def bar
f = lambda { return “return from lambda” }
f.call # control does not leave bar here
return “return from bar”

end

puts foo # prints “return from foo from inside proc”
puts bar # prints “return from bar”

Technorati Tags: , ,

Add comment July 23, 2008

“Bulk insertion of data with ActiveRecord”

Was just going through some blogs doing RnD here and there when I stumbled upon a blog at http://rubypond.com , felt awesome and hence thought of sharing with everyone.

have Cpt then entire post I hope its useful enough.

Its about pushing bulk insertions into the database using active records.
there are various ways , one is loop it the other is as follows which to me seems pretty cool.

Zach Dennis has written a great little plugin called ActiveRecord::Extensions which makes the bulk inserts almost as painless as your regular create.

First, install the gem:

sudo gem install ar-extensions

Include it in your app (you could put it in environment.rb if you’re going to use it a lot, for now I’ll place it in my model definition in user.rb:

require ‘ar-extensions’
class User
end

Then to use it, it really couldn’t be more straightforward. Use the following in your controller or rake task to import your data:

fields = [:first_name, :last_name, :email]
data = [["glenn", "gillen", "foo@bar.com"],
["john", "jones", "jim@bar.com"],
["steve", "smith", "bar@foo.com"]]

User.import fields, data

And we’re done, 3 new rows have been inserted into the users table, with just the single query. Any more questions, the RDocs are here

Chao!!!!!!!

Technorati Tags: , , ,

Add comment July 23, 2008

“Is ROR hot ? Yes maybe ,with new PORN sites emerging on ROR”

I dont have anything to say ,cumon its a Porn site you on ROR see it to believe it .

I dont know whether its legal or not , but the disclaimer says it is.

Heres the link! http://dominr.com .Watch out for your SYs Admin.

Technorati Tags: , ,

Add comment July 23, 2008

“What’s New in Edge Rails: Easy Join Table Conditions”

Just came across this new cool feature in edge rails…

For an application with anything above a moderate level of domain complexity it’s quite likely that you’ve had to perform a query utilizing a join table:

class Article < ActiveRecord::Base
belongs_to :user
end

class User < ActiveRecord::Base
has_many :articles
end

# Get all the users that have published articles
User.find(:all, :joins => :article,
:conditions => ["articles.published = ?", true])

t always makes me feel slightly embarrassed to have to resort to using String snippets to specify my query logic, and this little bit is no exception. Well, now we can specify conditions on a join table in a more concise manner:

# Get all the users that have published articles
User.find(:all, :joins => :article,
:conditions => { :articles => { :published => true } })

Note how you’re able to specify the join-table conditions as a hash whose key corresponds to the table or association name of the join table? You can now let Rails worry about forming the correct SQL condition even across complex joins.

However, don’t let the ease of this feature make you use it over a properly associated domain-model. For instance, this join query:

# Get all articles for a given user
Article.find(:all, :joins => :user,
:conditions => { :users => { :id => @user.id } })

is more appropriately represented as:

@user.articles

Technorati Tags: , , , ,

Add comment July 23, 2008

“Javascript made me feel like a IDIOT”

Today I was doing some javascript checks so that my regular price remains
always greater than the discounted price .

I check with normal arithmetic functions “==,<,>” to the $(“field_name”).value
and thought it has worked because that what was taught to me in my schools
that value 1 > value 2 returns true/false.

But all my prettiest school teachers were proven wrong by javascript.

I realized after releasing the code that
11> 10 => true
99.99 > 99.98 => true
212 > 212.21 => false

but they were also checking the number of digits.
So when I gave

10 > 9 => false
(It failed) …hmm even I had the same reaction!!!!

Man , what the S**T cum on how can this happen , then I thought
bro need to check javascripts arithmetic handlers once again ,
over there I came accross parseFloat and other functions.

check the link for more details

For the next two days I shall be wearing the “I was wrong ” Tshirt….

Technorati Tags: , , , , , , , , , , , ,

1 comment July 2, 2008

“Acts As Ferret DrbServer Win32 Service”

How to setup acts_as_ferret on windows was what I was wondering when I came accross this link.

In UNIX/LINUX the ferret server works as a process but for windows we need to generate a service to make it work.

Follow the below steps to make ferret work for you on windows.

1 / install latest verion of acts_as_ferret

2/Install win-32 service gem using

gem install win32-service

3/Download ferret_win32_service.zip and extract ferret_service and ferret_daemon

to [app_name]/ script directory. ferret_service script is to install/ remove/ start/ stop your win32 service, while ferret_ daemon script is to be called by Win32 service to start/stop the DrbServer.

4/ruby script/ferret_service install -n [service_name] -e production

5/ruby script/ferret_daemon

This should work fine, if needed please check .

Technorati Tags: , , , , ,

Add comment June 30, 2008

“How to check deprecations in rails using RAKE script”

With the new rails 2.+ versions out we feel the need to remove the deprecations from the present 1.2 rails application and make it compatible with rails 2.+ version.

For this firstly install the plugin for checking deprecations

/script/plugin install http://topfunky.net/svn/plugins/deprecated

</pre></blockquote>Then include the following script in the
<blockquote><pre>libs/tasks/rails.rake file 

and then run rails deprecated on the command prompt on your root folder.
This will return all the deprecations in the application.
Remove one by one all the deprecations and then check again doing the same till we dont get any deprecations in the application.

Now your application is ready to move to 2.0 just change the extensions of the files using another script and thats it , wallah rails 2.+ ENJOY it!!!!!

Heres the script.Copy paste in the libs/tasks/rails.rake file

Thanx .
CJTechnorati Tags: , , , , ,

Add comment June 24, 2008

“Memorizing Ruby on Rails: “

This is a free resource (that was built on RoR) that’s helpful for
learning and
memorizing Ruby on Rails:

http://www.yoyobrain.com/cardboxes/preview/863

If you click on “Try a learning drill” -the site will quiz you on
Rails information to help you learn more efficiently- pretty cool.

Please feel free to suggest how to make this more valuable to people
who want to learn Ruby on Rails (and any other programming language
for that matter), corrections to the flashcards, how to get the word
out, etc.

I hope you find it useful, and can’t wait to hear your feedback. Technorati Tags: , , ,

Add comment June 22, 2008

“Formatting Date field using ruby”

You can format Date field by using strftime function

example :

Time.now()

=> Wed Dec 12 15:48:59 +0530 2007

Time.now().strftime(”%d/%m/%y %H:%M”)
=> “12/12/07 15:50″

Here’s the (shortened) table for strftime.

%a weekday name.
%A weekday name (full).
%b month name.
%B month name (full).
%c date and time (locale)
%d day of month [01,31].
%H hour [00,23].
%I hour [01,12].
%j day of year [001,366].
%m month [01,12].
%M minute [00,59].
%p AM or PM
%S Second [00,61]
%U week of year (Sunday)[00,53].
w weekday [0(Sunday),6].
W week of year (Monday)[00,53].
x date (locale).
%X time (locale).
%y year [00,99].
%Y year [2000].
%Z timezone name

Technorati Tags: , , , ,

Add comment June 20, 2008

Previous Posts


Recent Posts

Tags

Active Record australian gp calendar date select capistrano capitalize debugging Debugging in rails edge rails formula 1 For those who dont want to update the prototype.js fun Fun baby fun google html in join javascript linus vs windows compatibility linux logging love song malaysian gp 2008 results melbourne migrations music mysql plugin poetry rails regexp regular expression results formula 1 opening race romantic poetry ror Ruby ruby on rails safe html sms song SQL string case handler for strings syantax syntax error for migrations on linux Text Area they can checkout 1.8.3 of the calender date select

Blogroll

Pages