Rails-Dynamic-DropDown

I have found many codes and blog posts for dynamic drop down with mysql in rails. But I want to implement it with mongoid in my application. Many codes that I found are not perfectly working for this. Some gave me problem of non appearing data during edit. So I tried to develop my own dynamic drop-down with mongoid in rails. Finally I become success to implement full featured rails dynamic drop down with mongoid and coffeescript.

Find the source code in github:

https://github.com/gkunwar/dynamic-dropdown

Getting Started

First of all you make sure that mongodb is installed.

Clone

If you want to copy and customize the app with changes that are only useful for your own project, you can clone the GitHub repo. You probably should generate the app instead (see below). To clone:

$ git clone git://github.com/gkunwar/dynamic-dropdown.git

Then install the bundle and run the application.

Stored Procedures and Rails - Part 1

Reblogged from Nasir Jamal:


There is no documentation in Rails about how to use stored procedures or atleast it is difficult to find where to look at. And according to DHH stored procedures is not the Rails Way to do things. DHH mentioned in his post

I want a single layer of cleverness: My domain model. Object-orientation is all about encapsulating clever. Letting it sieve half ways through to the database is a terrible violation of those fine intentions.

Read more… 302 more words

Stored Procedures and Rails

How to implement the dynamic authorization with CanCan ?

Reblogged from Eve Love Rails:

I have used CanCan plugin to manage authorization on my rails app, but it’s still static authorization. I just create code like this:

My app is getting bigger. There are users with many user types. Every user type has different role / authorization. I’d like to create a feature that user admin can manage authorization for all user types. Admin can assign or remove the permission to each user types.

Read more… 562 more words

How to implement the dynamic authorization with CanCan ?

MongoDB, Mongoid and Map/Reduce

Reblogged from What You're Doing Is Rather Desperate:

I've been experimenting with MongoDB's map-reduce, called from Ruby, as a replacement for Ruby's Enumerable methods (map/collect, inject). It's faster. Much faster.

Next, the details but first - the disclaimers:

  • My database is not optimised (using, e.g. indices)
  • My non-map/reduce code is not optimised; I'm sure there are better ways to perform database queries and use Enumerable than those in this post…

Read more… 1,219 more words

Ruby Arithmetic Operation for Date

I wanted to get the difference between two dates. My date are in format “DD/MM/YYYY”. I tried to get number of days between two date of same format. Finally I got an easy method to get number of day between these two date.

For this first of all I changed these date to date format using following method.

d1 = “12/2/2012″
d2 = “15/2/2012″
d1 = d1.to_date
d2 = d2.to_date
no_of_days = (d2-d1).to_i

Finally, I get number of days between two date. If there are any better methods for this operation, suggestions are welcome.

The Definitive Guide to accepts_nested_attributes_for a model in rails 3

Reblogged from Experience Satire:

accepts_nested_attributes_for is very useful when you want a single form to cater to multiple models. It gives you an easy way to include attributes from the associated tables and also to successfully save and delete objects.

Consider a scenario where 'House' has many 'Rooms'  and has one 'Address'. It also belongs to an 'Owner'. Now suppose you want a single form for house which is able to present attributes for room, address and user and also is able to save it successfully.

Read more… 293 more words

The Definitive Guide to accepts_nested_attributes_for a model in rails 3