0

Good day.
How to add params[:controller] value in params[:comments]. (in View)
I want the comment Model will be filled with following parameters:

#comment.rb

id: 
text:
commentable_id:
user_id:
controller: #for example 'posts', or 'galleries'

But a User doesn't have access to controller: value.
controller: should be determined by default. (for example posts)

Something like there http://railscasts.com/episodes/154-polymorphic-association
but commentable_type: is swaped with controller:

And how do you think, is it good emplemention of polymorpyc assosiation for comments ?
How emplement this solution better?

itsnikolay
  • 17,415
  • 4
  • 65
  • 64
  • Why do you want to replace commentable type with controller? By the way you can access controller name in view like that: controller.controller_name – emrahbasman Sep 03 '12 at 21:32
  • Your explanations are really unclear. Can you try to describe what you're trying to achieve without talking about implementation? – Robin Sep 03 '12 at 21:36
  • The best way to implement it is to follow the Railscast you are linking to. – Mischa Sep 04 '12 at 00:13

1 Answers1

0

The controller name shouldn't dictate what is done in the Model.

So keep the polymorphic association for comments and you can change the route name to be whatever you want to suit your situation.

In your form, you are going to POST to some create action, which will dictate the model where you can choose 'posts' or 'galleries'.

pjammer
  • 9,489
  • 5
  • 46
  • 56