Re: Problem with RoR''s controller getting too large

Klondike
Wed, 02 May 2007 06:08:05 -0000

shurain,

By making a controller for each model, this doesn''t mean you
can''t
deal with other models in the views related to that controller.

In your situation, your comment controller may have only 3 actions:
create, update, and destroy, all of which are reached through form
submissions.  In that case, your comments controller would control no
views!

But this is fine -- put actions in the comment controller which
*primarily* deal with comments, and actions in the posts controller
which *primarily* deal with posts.  That''s the best you, or any of us,
can do -- and it works just fine.

-- Eric

On May 2, 12:58 am, "Daniel N"
<has....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
> On 5/2/07, shurain <shur...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
>
>
>
> > Let me rephrase the problem.
>
> > I wish to be able to show an article using postcontroller.
> > I would also like to create a comment using commentcontroller.
> > I want to see them both in one view.
>
> I''m not sure what the issue is.   Michael is correct when he says
you can
> have as many controllers as you like.
>
> If you want to see both a post and comment in one view use partials
>
> eg something like (posts)
>
> def show
>   @post = Post.find_by_id( :id )
> end
>
> in your view
>
> <%= display stuff for posts -%>
>
> <%= render :partial => ''/comment/detail'',
:collection => @post.comments %>
>
> Is that along the lines of what your after?