简体   繁体   English

Ruby on Rails:在视图中进行更改后,网站不会更新

[英]Ruby on Rails: After change in view, website not updating

I don't think I quite understand how rails updates its view pages. 我不认为我非常理解rails如何更新其视图页面。 I have deleted a piece of code in my index view, and when I go to refresh page, the code is still present. 我在索引视图中删除了一段代码,当我转到刷新页面时,代码仍然存在。 I tried restarting the server, and I can't think what else to do. 我尝试重启服务器,我想不出还有什么可做的。 Must be a simple thing that I haven't learnt yet, as I'm new to rails. 必须是一件我尚未学到的简单事情,因为我是铁杆新手。 Thanks 谢谢

EDIT: 编辑:

Routes 路线

    projects GET    /projects(.:format)          projects#index
             POST   /projects(.:format)          projects#create
 new_project GET    /projects/new(.:format)      projects#new
edit_project GET    /projects/:id/edit(.:format) projects#edit
     project GET    /projects/:id(.:format)      projects#show
             PUT    /projects/:id(.:format)      projects#update
             DELETE /projects/:id(.:format)      projects#destroy
      search        /search(.:format)            projects#search
        root        /                            projects#index

config/routes.rb: 配置/ routes.rb文件:

FinalApp::Application.routes.draw do
    resources :projects
    match "search" => "projects#search", :as => :search
    root :to => 'projects#index'
end

Index action in Project Controller: 项目控制器中的索引操作:

def index
    @projects = Project.all



respond_to do |format|
      format.html # index.html.erb
      format.json { render :json => @projects }
    end
  end

If it stays the same after editing the html, you are not viewing what you think you are viewing. 如果在编辑html后它保持不变,则表示您没有查看您认为正在查看的内容。

  • Maybe you have both a index.html.erb and a index.html.haml file? 也许您同时拥有index.html.erb和index.html.haml文件?
  • Are you sure you did not accidently copy the index.html.erb outside the app/views/projects/ folder, so Rails takes the one in that location? 你确定你没有意外地将index.html.erb复制到app / views / projects /文件夹之外,那么Rails会占用那个位置的那个吗?

尝试删除应用公用文件夹中的index.html文件。

确保config/routes.rb指向正确的控制器和操作。

I was doing a tutorial and had run rails server in the directory outside of app . 我正在做一个教程,并在app之外的目录中运行rails server I'm pretty sure I stopped and started the server a couple of times, navigated around directories, then I made some changes and they weren't showing. 我很确定我已停止并启动服务器几次,浏览目录,然后我做了一些更改而他们没有显示。 I stopped the server, changed into app then started the server again, I got what I expected. 我停止了服务器,更改为app然后再次启动服务器,我得到了我的预期。 If you're having trouble, it might be worth checking that. 如果您遇到麻烦,可能值得检查一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM