Code organization for Rails models accessed in different views

I am confused about where I should put code for a model that is modified in the view for another controller. Huh? Here's the situation:

I have a Phone model and an associated controller. In the Phones view you can modify simple things like who the Phone is assigned to. In order to change more low-level things about the Phone, you have to go to the Settings screen, which has its own controller.

I have partials that are used to render information about Phones in the Settings screen. Should these be kept in the app/views/settings directory or app/views/phones? What about partials that are used in both views?

Also, if there is an action in the Phones controller that is only accessible from the Settings screen, should I keep the response (eg destroy.js.erb) in app/views/settings or app/views/phones?

-------------Problems Reply------------

I know this is an old question... but here is what I do:

It is perfectly okay to have several controllers accessing the same model. I personally would put the phone partials that are used by the settings controller with the rest of the phone partials. If you have partials that have no logical home and are used in multiple views, you can always create a new folder in /app/views/ to house your shared stuff.

Regarding the destroy.js.erb, that one is a little more tricky... I don't know if there is one right way to do it.

In the end, do whatever makes the most sense.

Category:ruby on rails Views:1 Time:2010-09-24

Related post

  • Connecting a Rails model to a database view? 2011-03-31

    I've heard that you can tie a model in rails to a database view (instead of a table as per usual) and that this is dome simply by creating a view with the name that the model's table would ordinarily have. I am not getting this to work in rails 3.0.5

  • How to organize a Backbone model used by multiple views? 2012-02-29

    So here is the skinny...(I always talk like a 30s gangster) I have two Models - ya seee: Company + Date Setup The Company model is attached to a drop down list view. It fetches the list of companies from the server. Date is set to today and is attach

  • Rails model passes validation but view still renders errors? 2010-01-17

    Oddly enough, my model passes validation just fine, and acts as expected, however I still have the error rendered to the view. # Controller def up @vote = Vote.create :vote => true, :voter => current_user, :voteable => Recipe.find(params[:id

  • Rails Models - Can they have helpers? that allow for rendering a view? 2011-06-12

    In a rails 3 model. can I use a helper? If so how. And in that helper can I render a view allowing me to store the view in the db? Thanks --------------Solutions------------- If storing your views in the DB is what you are after you shouldn't have to

  • Accessibility and code organization problems in javascript with jquery 2009-08-05

    I'm having troubles with the order of my code in my program. right now I have some things with in document.ready(function() { } ); and some things out side of it. Whenever I move anything (to organize or improve my code) I end up breaking something,

  • What kind of information can the Model access in Rails? 2011-01-12

    In Ryan Bates's first episode on complex forms, he adds the following to a model: # models/project.rb has_many :tasks def task_attributes=(task_attributes) task_attributes.each do |attributes| end end I've never thought about

  • accessing rails models from rake task 2011-06-23

    How can I access model objects from rails rake task? If I initialize my rufus scheduler $scheduler = Rufus::Scheduler.start_new in my rake would that scheduler stay alive since it's from a rake task? --------------Solutions------------- To access a r

  • avoiding code duplication in Rails 3 models 2011-11-30

    I'm working on a Rails 3.1 application where there are a number of different enum-like models that are stored in the database. There is a lot of identical code in these models, as well as in the associated controllers and views. I've solved the code

  • Code organization in JavaScript: MVC? Self-rendering components? 2011-03-18

    I'm building an extremely JS-heavy web application. I say it's JS-heavy, because the vast majority of the work going on is done on the client (although there is some syncing back and forth to the server using AJAX and XMPP). This is my first time bui

  • How to externalize Rails model (api/gem/plugin) 2012-01-01

    currently I am working on a RoR application (2.3.14 with ActiveRecord) (let's call it A). Now I started another project B (a remote testing app using capybara, looks something like this: Bu

  • Commonly accepted best practices around code organization in JavaScript 2008-10-29

    As JavaScript frameworks like jQuery make client side web applications richer and more functional, I've started to notice one problem... How in the world do you keep this organized? Put all your handlers in one spot and write functions for all the ev

  • Can I define_method in rails models? 2008-11-19

    My rails model has code that is attempting to define_method(method_name) inside the model. I keep getting: NoMethodError: undefined method `define_method' What am I doing wrong? Am I doing this in the wrong place. I need this method attached to this

  • Ruby on rails model and controllers inside of different namespaces 2009-05-24

    OK. This is insane. I'm new to RoR and I really want to get into it as everything about it that I have seen so far makes it more appealing to the type of work that I do. However, I can't seem to accomplish a very simple thing with RoR. I want these c

  • What test framework should I use to test my Rails model? 2009-10-13

    With the many testing framework that is available in the Ruby community namely: unittest, rspec, shoulda, and coulda, what would be the most appropriate testing framework to test my Rails model? Do they basically have the same functionality, which is

  • Django: How would one organize this big model / manager / design mess? 2010-01-25

    To sum things up before I get into bad examples, et al: I'm trying to make an application where I don't have to write code in all my models to limit choices to the current logged in account (I'm not using Auth, or builtin features for the account or

  • Rails - validates_uniqueness_of: access duplicate item? 2010-07-01

    I have a basic Rails model with two properties, name and code. I have validates_uniqueness_of for the code property. However, I'd like to customize the :message to show the name of the duplicate. Is there any way to access this duplicate item? For ex

  • How do I return an array of attributes defined via a Rails model method, as well as the attributes in the database table? 2010-11-09

    I have a Rails model called Person which has database table columns for first_name and last_name. I've also defined a full_name method to return the combined first_name and last_name of the instance. Is there a way to return an array, hash, or object

  • Differences between *, self.* and @* when referencing associations/attributes in Ruby/Rails Models/Controllers 2011-06-24

    Assuming a Rails Model with persistent / non-persistent attributes, what is the best practice regarding referencing them? If you look at code publicly available, different patterns are used. For instance, if you have an association from one model to

  • Rails Models: how would you create a pre-defined set of attributes? 2011-06-30

    I'm trying to figure out the best way to design a rails model. For purposes of the example, let's say I'm building a database of characters, which may have several different fixed attributes. For instance: Character - Morality (may be "Good" or "Evil

Copyright (C), All Rights Reserved.

processed in 0.088 (s). 11 q(s)