Sattu wrote:
> hi all,
> 
>      I am trying to implement a website on the mobile device. The
> website is written in RoR and currently runs for desktop and laptop
> users.
> I have started learning RoR with Instant Rails. Could anyone guide me
> about how should i move forward, like any references, what points to
> consider for designing?

Okay, here are the basics to get you started. As you may or may not know 
there was a time when rails templates used the .rhtml extension. 
Beginning with Rails 2.0 (I think) templates began using a new naming 
convention such as .html.erb. This change separates the engine (erb in 
this case) from the markup (html).

The primary reason for this change was to provide an elegant solution 
for just what you're trying to accomplish.

The heart of the solution is wrapped up in the respond_to method of 
Rails controllers. You might have seen something similar to the 
following:

def index
  @people = Person.find(:all)

  respond_to do |format|
    format.html
    format.xml { render :xml => @people.to_xml }
  end
end

In order to support other templates using HTML you would add your own 
"format" and MIME type.

So the respond_to could be extended to include the alternate "mobile" 
layouts:

def index
  @people = Person.find(:all)

  respond_to do |format|
    format.html
    format.mobile
    format.iphone
    format.xml { render :xml => @people.to_xml }
  end
end

With these MIME types added in order to inform Rails of the new types:

---------------
environment.rb
---------------
Mime::Type.register "text/mobile", :mobile
Mime::Type.register "text/iphone", :iphone

Then your templates would be named accordingly:

index.mobile.erb
index.iphone.erb

You can then use the ACCEPTS header or URL extension just like you would 
for the XML representation:

http://localhost:3000/posts.mobile
http://localhost:3000/posts/1.iphone
etc.

Then you simply use Embedded Ruby (erb) with HTML to create your mobile 
and iphone (or any other alternate layouts) you want.
-- 
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to