Recent Posts

Showing posts with label Ruby on Rails. Show all posts
Showing posts with label Ruby on Rails. Show all posts

Sunday, June 6, 2010

Date functions for Ruby on Rails

d = Date.today # 2008-08-12
d.strftime(‘%b %d, %Y’) # will print August 12, 2008
The following date format is derived from this site.

Date Format Meaning
%a The abbreviated weekday name (“Sun’’)
%A The full weekday name (“Sunday’’)
%b The abbreviated month name (“Jan’’)
%B The full month name (“January’’)
%c The preferred local date and time representation
%d Day of the month (01..31)
%H Hour of the day, 24-hour clock (00..23)
%I Hour of the day, 12-hour clock (01..12)
%j Day of the year (001..366)
%m Month of the year (01..12)
%M Minute of the hour (00..59)
%p Meridian indicator (“AM’’ or “PM’’)
%S Second of the minute (00..60)
%U Week number of the current year, starting with the first Sunday as the first day of the first week (00..53)
%W Week number of the current year, starting with the first Monday as the first day of the first week (00..53)
%w Day of the week (Sunday is 0, 0..6)
%x Preferred representation for the date alone, no time
%X Preferred representation for the time alone, no date
%y Year without a century (00..99)
%Y Year with century
%Z Time zone name

time = Time.new

# Components of a Time

puts "Current Time : " + time.inspect
puts time.year # => Year of the date
puts time.month # => Month of the date (1 to 12)
puts time.day # => Day of the date (1 to 31 )
puts time.wday # => 0: Day of week: 0 is Sunday
puts time.yday # => 365: Day of year
puts time.hour # => 23: 24-hour clock
puts time.min # => 59
puts time.sec # => 59
puts time.usec # => 999999: microseconds
puts time.zone # => "UTC": timezone name


Read more!

Wednesday, January 13, 2010

Some useful links for Ruby on Rails development

How to deploy your ruby on rails application on web server?

http://www.vaporbase.com/postings/Deploying_my_first_rails_site

To use flash object in your rails application

http://www.railslodge.com/plugins/283-flash-object


Read more!

Monday, January 11, 2010

How to install rails plugin behind the proxy

I was facing problem installing my rails plugins behind windows proxy

It was giving me plugin not found error all the time i tried to install a new plugin

after research setting http_proxy in command prompt as belows solved my problem

set http_proxy=http://username:password@proxy:8080


Read more!

Monday, October 26, 2009

Simple steps listed to create a ruby on rails application

This article lists all the steps required to create a simple web site in ruby on rails.
This article a fast track approach in developing a ruby on rails website.

First download and install the ruby on rails. If you haven't yet then you can go to Ruby on rails website and then download and install and start mysql and Apache web server that can be done by starting InstantRails.exe in the Instant rails folder.

Now go to command prompt and enter use_ruby

This will take you to rails application path if ruby on rails has been installed properly in the drive.
Then follow the following steps to create a complete website:

1 . rails AppName

2. Change database.yml file to point to required database

3. rake db:create:all Creates the database
4. ruby script/generate scaffold Table1 column1:string column2:text column3:integer

5. ruby script/generate scaffold Table2 column1:string column2:text column3:integer

6. change db/migrate/ 001_create_table1.rb file specify the limit and add t.references :table2 for foreign key

7. rake db:migrate

8. Open up modals and setup Active record base for recipie and category.

9. put has_many :recipes in category ActiveRecord:: base

10. put belongs_to:category in reciepe ActiveRecord:: base

11. go to public folder and delete index.html

12. open routes.rb file from config folder and find map.root and enable that portion.

13. Set map.root :controller => "categories"

14. Now open C:\InstantRails-2.0\rails_apps\astroun\app\views\categories\new.html.erb and
C:\InstantRails-2.0\rails_apps\astroun\app\views\recipie\new.html.erb

15. delete the portion between <% form_for(@recipe) do |f| %>
<% end %> from recipie.

16. create a new file called _form.html.erb which is partial and it renders the form.

17. Paste the portion deleted in new.html.erb into this new file _form.html.erb and

18. Now put the render code in the deleted portion of new.html.erb :
<%= render :partial => "form", :locals => { :f => f, :button => "Create" } %>

19. And similarly in edit.html.erb put
<%= render :partial => "form", :locals => { :f => f, :button => "Update" } %>

20. Now run and see by doing ruby script/server and run http://localhost:3000/

21. Scaffold creates layouts in views that can be delted and modified as per need.

22. Lets delete these files in layout folder and create application.html.erb as application wide layout.

23. Now it works fine but with one problem if there are reciepies in category but if we destroy the category then when we try to list the recipies that throws error because category is not there.

24. To fix this make changes in categories_controller saying if it has items in it then don't destroy the category.








Read more!

Tuesday, July 7, 2009

Connection attempt Failed for Ruby gem update --system (Solved for windows users)

I encountered while trying to update ruby gem and took my more than 1 hour to search for the solution and have to go through lots of blogs and scroll through the comments to finally get the right answer.

When i did gem update --system then i got the following error:

ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
A connection attempt failed because the connected party did not properly res
pond after a period of time, or established connection failed because connected
host has failed to respond. - connect(2) (Errno::ETIMEDOUT)
getting size of http://gems.rubyforge.org/Marshal.4.8

Solution

So this might be due to the connection to the site or the proxy problem

1 Go to your IE Internet options/connections/Lan Settings/

2. Check your proxy and its port

3. go to Command prompt and do

set http_proxy=http://proxy:port

Now do gem update --system

Should work now.....



Read more!

Monday, June 1, 2009

Solve undefined method `render_text' in Ruby on rails

I have just started to work on Ruby on Rails and was going through step by step Ruby on rails tutorial. 

As i went through I got on to undefined method `render_text' .... Now what ???

so looking into various web sites I Finally got it

You can use

render :text =>"Hello World" Instead of render_text


Enjoy learning ruby


Read more!