Understanding MVC Architecture as a Non-MVC Developer

I have a problem understanding MVC architecture. It is not that I know nothing about MVC. Everything makes sense to me in the MVC architecture, but if I want to start developing my application in the MVC architecture, I'm stuck.

Basically, there are many ways to do what you want in the programming world, but I want to do it as intended. So maybe there is someone who can help me.

But here is my recent problem with MVC:

I want to write my own blog on Ruby on Rails. I think this is not a big problem. I would have models like articles, comments, user and more. For each of them, I would create a controller to manage them and everyone. The problem is when it comes to the admin panel. I want the article to be created only in the admin panel.

So what should I do? Should I create an admin panel controller to manage all these tasks that can only be performed in the admin panel? Otherwise, I think this is too much for a single controller.

I want my urls to look something like this:

For Admin-Panel Tasks: example.com/admin/article/create For Viewers: example.com/article/show

(I think Rails calm routes look different, but I think you get what I want)

MVC ? MVC?

.

+3
2

, -, - 1) URL-/admin, , 2) ActionController

, , , RESTful ( Rails 3):

# routes.rb
resources :users
resources :posts
resources :pages

namespace :admin do |admin|
  match '/' => 'dashboard#index'
  resources :users
  resources :posts
  resources :pages
end

, , /admin/users/new /admin/posts/1, .. , " ", 'm Admin:: DashboardController

, ApplicationController. , :

class Admin::BaseController < ApplicationController
  before_filter :require_user
  layout 'admin'
end

/ "admin". , :

# pages_controller.rb
class Admin::PagesController < Admin::BaseController
  # Controller code in here
end

/ "admin", - , / , .

"-", .

, !

+4

, , . , , . , , , , ..

, (.. ), , . , .

Rails . , .

0

Source: https://habr.com/ru/post/1760074/


All Articles