繁体   English   中英

Rails 4:从index.html.erb访问所有CRUD

[英]Rails 4: Access all CRUD from index.html.erb

我正在尝试仅创建一个1页索引站点。 我想处理创建,删除,编辑1个索引中的所有内容。 (非常基础)

但是,我遵循了初学者的入门指南: http//guides.rubyonrails.org/getting_started.html

我的文章控制器示例:

def index
 @articles = Article.all #Create Articles and then add the for loop inside the index.html
 @article = Article.new
end

def create
  @article = Article.new(article_params)
  if @article.save
  redirect_to @article
 end
end

def new
 @article = Article.new
end 
...

private
def article_params
 params.require(:article).permit(:title, :text)
end

我使用@articles填充所有已添加的文章。 然后@article到CRUD。 除了无法从index.html页完全控制CRUD。

<form role="form" class="form-inline">
    <div class="form-group">
      <%= form_for @article do |f| %>

          <div class="form-group">
            <label for="textUserInputDescription"><%= f.label :title %><br/><%= f.text_field :title %>
            </label>
            <label for="textUserInputDescription"><%= f.label :text %><br/><%= f.text_area :text %> </label>
            <button type="submit" class="btn btn-default"><%= f.submit %></button>
          </div>
    <% end %>
  </div>

当我单击提交时,它不会添加到我的数据库中。

我的问题是:如何从index.html内访问CRUD?

感谢您的宝贵时间,我仍在学习Rails / CRUD / ActiveRecord和后续教程。

我将f.submit更改为:

<%= button_to "Create", new_article_path(@article[:title], @article[:text]), method: :post %>

暂无
暂无

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

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