# Help on ruby on rails for mobile website development

**URL:** <https://www.ruby-forum.com/t/help-on-ruby-on-rails-for-mobile-website-development/175173>\
**Category:** Rails\
**Created:** [September 9, 2009, 9:43am UTC](https://www.ruby-forum.com/t/help-on-ruby-on-rails-for-mobile-website-development/175173 "2009-09-09T09:43:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sattu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@Sattu](https://www.ruby-forum.com/u/Sattu)\
**Post date:** [September 9, 2009, 9:43am UTC](https://www.ruby-forum.com/t/help-on-ruby-on-rails-for-mobile-website-development/175173/1 "2009-09-09T09:43:01Z")

</div>

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?

Thanks and Regards,  
Sattu

---

<div class="post-metadata">

**Author:** ![Sattu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@Sattu](https://www.ruby-forum.com/u/Sattu)\
**Post date:** [September 9, 2009, 3:23pm UTC](https://www.ruby-forum.com/t/help-on-ruby-on-rails-for-mobile-website-development/175173/2 "2009-09-09T15:23:23Z")

</div>

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.mobile)  
[http://localhost:3000/posts/1.iphone](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.

---

<div class="post-metadata">

**Author:** ![Sattu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@Sattu](https://www.ruby-forum.com/u/Sattu)\
**Post date:** [September 9, 2009, 3:27pm UTC](https://www.ruby-forum.com/t/help-on-ruby-on-rails-for-mobile-website-development/175173/3 "2009-09-09T15:27:01Z")

</div>

Robert W. wrote:

> 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.mobile)  
> [http://localhost:3000/posts/1.iphone](http://localhost:3000/posts/1.iphone)  
> etc.

Oops. These URL should have been for people rather than posts to match  
the rest of the example:

[http://localhost:3000/people.mobile](http://localhost:3000/people.mobile)  
[http://localhost:3000/people/1.iphone](http://localhost:3000/people/1.iphone)  
etc.

---

<div class="post-metadata">

**Author:** ![Sattu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@Sattu](https://www.ruby-forum.com/u/Sattu)\
**Post date:** [September 9, 2009, 4:57pm UTC](https://www.ruby-forum.com/t/help-on-ruby-on-rails-for-mobile-website-development/175173/4 "2009-09-09T16:57:25Z")

</div>

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?
> 
> Thanks and Regards,  
> Sattu

It may be that your website will already work well in mobile browsers.  
Check before you do any further development.

And for God’s sake, if you do have to make a mobile site, provide a link  
to the full site. Some of us really hate crippled functionality.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Sattu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@Sattu](https://www.ruby-forum.com/u/Sattu)\
**Post date:** [September 9, 2009, 6:46pm UTC](https://www.ruby-forum.com/t/help-on-ruby-on-rails-for-mobile-website-development/175173/5 "2009-09-09T18:46:46Z")

</div>

Marnen Laibow-Koser wrote:

> And for God’s sake, if you do have to make a mobile site, provide a link  
> to the full site. Some of us really hate crippled functionality.

+1

---

<div class="post-metadata">

**Author:** ![Sattu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@Sattu](https://www.ruby-forum.com/u/Sattu)\
**Post date:** [September 9, 2009, 4:25pm UTC](https://www.ruby-forum.com/t/help-on-ruby-on-rails-for-mobile-website-development/175173/6 "2009-09-09T16:25:50Z")

</div>

Hi Sattu,

On Tue, 2009-09-08 at 20:08 -0700, 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.

If I understand your question correctly, I’d recommend that you google  
‘web design for mobile devices’ as a starting point. You’ll also need  
to learn to identify user agents and, more importantly, to identify  
client capabilities. CSS and Javascript will become important tools in  
your kit. If you’re not already fluent in those, focus some effort on  
becoming so.

HTH,  
Bill
