On 19 April 2015 at 08:14, Padmahas Bn <padma...@gmail.com> wrote:
> Hello all, I referred the rails guides from documentation section, but I
> cannot solve this problem.
>
> Problem:
> 1. I have member and receipt model (which should have corresponding members
> and receipts table).
> 2. Now I created a model called recovery to write some business logic.
> (logic must be in models right?)

It depends on the logic

> 3. And I have not created any association between any of the models.

Why not?  Are they not related?

>
> What I want to do:
> 1. I just want to retrieve all the member_code from members table whose
> 'status' is "active" from within recovery model.

Member.where(status: "active")
will give you the members, then you can use each to get member.member_code

> 2. Once all member_code are available I want to compare those member_code
> with the member_code of receipts table. If those member_code exists in
> receipts table, I'll run some business logic only on those members.

Just compare them, what is the problem.  However if you have the same
information in two models it is very likely that you database design
is poor.  What is a member_code?

>
> So all I want to do is access the attributes of members and receipts table
> from recovery model and I have created a button "start recovery process" in
> view.html.erb of recoveries. I would like to execute the business logic
> written inside recovery model once I press this button.
> How can I point the button to the code inside model? Because by default it
> will pointing to actions inside controller right?

I think maybe you are missing some of the fundamentals of rails.  I
suggest that before doing anything else you work right through a good
tutorial such as railstutorial.org (which is free to use online),
including all the exercises.  That will show you the basics of rails.

>
> Can I do this without creating associations? Or is it compulsory?

Nothing is compulsory.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLvu6_PgUbzGR52B0sVBrQsP7V8%3DMyc7gxufEPYbSfyAZw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to