I need to call an action inside of a controller from a method inside of a model. This is something I do a lot in other language (when working with the MVC framework), however, I've never seen this done in ruby on rails. The action doesn't render anything, it simply updates a session variable.
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- Eager-loading association count with Arel (Rails 3
- How to dynamically load partial view Via jquery aj
- Is there a way to remove IDV Tags from an AIFF fil
相关文章
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
- Rspec controller error expecting <“index”> but
- Factory_girl has_one relation with validates_prese
That's not really something you would normally do in the MVC pattern. Your Model should really only house business logic (and data access). Can you supply some information about what you're trying to call and why? Usually when you're trying to do something like this, it's a smell that something isn't where it's supposed to be.
This is usually the way I see it:
If you're trying to call something in a controller from a model, it might mean there's too much controlling logic in your model.
Or, perhaps, you've just got a method that could be used everywhere (it's a helper method, and it's actually unrelated from the model and your controller). In this case, you should put it in its own module in your /lib directory.
Edit: Yeah, session variables should probably only be touched/updated in the Controller. Perhaps you have too much control-type logic in your model? Maybe rethink how closely that logic is related to the actual Model if its actually part of the Controller's action.
If you want call controller action (or cahange session because
session
is defined as@session
variable and it's private) from model you should pass controller instance as a param to model's method so if you do need editsession
method may be similar toin controller