Ruby on rails Ruby索引和显示视图未显示任何数据

Ruby on rails Ruby索引和显示视图未显示任何数据,ruby-on-rails,ruby,Ruby On Rails,Ruby,我是Ruby新手,我正在Nitrous中开发自己的应用程序 当我在new.html.erb上完成表单并点击save时,将加载show视图。页面按预期呈现HTML标题,但没有来自我的模型的数据字段。我也尝试过索引视图,但我认为没有保存任何数据 我已经生成了一个名为income的模型,并在设置了正确的表的情况下成功运行rakedb:migrate。我弄不清问题出在哪里 任何想法都受到了感激 这是我的控制器:www.u controller.rb class IncomesController <

我是Ruby新手,我正在Nitrous中开发自己的应用程序

当我在new.html.erb上完成表单并点击save时,将加载show视图。页面按预期呈现HTML标题,但没有来自我的模型的数据字段。我也尝试过索引视图,但我认为没有保存任何数据

我已经生成了一个名为income的模型,并在设置了正确的表的情况下成功运行rakedb:migrate。我弄不清问题出在哪里

任何想法都受到了感激

这是我的控制器:www.u controller.rb

class IncomesController < ApplicationController 

  def index
  @incomes = Income.all
end

def new
  @income = Income.new
end

def create
 @income = Income.new(income_params)
 if @income.save
  redirect_to(:action => 'show', :id => @income.id)
 end
end

def show
 @income = Income.find(params[:id])
end


private

def income_params
 params.require(:income).permit(:first_name, :last_name, :date_of_birth, :income1, :income2, :income3, :income4, :income5, :income6, :income7, :income8, :income9, :income10)
 end
end

感谢@RailsOuter和@jyrkim的帮助。我发现问题确实出在我的模型文件和迁移文件上

我需要从模型中删除行属性访问器。后来我发现,我必须修改迁移文件以添加列,而不是生成新的迁移。现在我已经用数据列生成了新的迁移,我的数据正在显示


再次感谢,非常感谢您为帮助新手所做的贡献

重定向到(:action=>'show',:id=>@income.id)
将create中的这一行替换为这一行,然后尝试
重定向到@post,注意:'income已成功创建。
在show页面中只需打印
@income
值谢谢。我在点击save后收到错误:“ActionController::ActionControllerError in IncomesController#create无法重定向到nil!”想法?您的收入是否保存到数据库中?您使用的rails版本是什么?如果4,那么你不需要这行属性访问器:名字、姓氏、出生日期、收入1、收入2、收入3、收入4、收入5、收入6、收入7、收入8、收入9、收入10据我所知,我的强势参数非常紧张。。。
<%= simple_form_for @income do |f| %>  
    <%= f.input :first_name, label: 'First Name' %> 
    <%= f.input :last_name, label: 'Last Name' %> 
    <%= f.input :date_of_birth, label: 'Date of Birth', hint: 'dd/mm/yyyy' %> 

<p>Income: Salary or Wages</p>
<%= f.input  :income1, label: 'Take home salary or Wage' %>
<%= f.input  :income2, label: 'Partner\'s salary or wage' %>
<%= f.input  :income3, label: 'Other income from salary or wages' %>

<p>Other Income</p>
<%= f.input  :income4, label: 'Maintanence or child support' %>
<%= f.input  :income5, label: 'Boarders or lodgers' %>
<%= f.input  :income6, label: 'Non-dependent contributions' %>
<%= f.input  :income7, label: 'Student loands or grants' %>
<%= f.input  :income7, label: 'Other' %>

<p>Benefits </p>
<%= f.input  :income8, label: 'Sample input' %>
<%= f.input  :income9, label: 'Sample input' %>
<%= f.input  :income10, label: 'More sample inputs' %>

<%= f.button :submit, "Save and Proceed" %>
<h3>You will have a chance to review your form before you submit it.  Once you click Save, you can come back and complete the rest of the form at a later date</h3>

<% end %>
<p>
  <strong>First name:</strong>
  <%= @income.first_name %>
</p>

<p>
  <strong>Last name:</strong>  
  <%= @income.last_name %>
</p>

<p>
  <strong>Date of Birth:</strong>  
  <%= @income.date_of_birth %>
</p>

<p>
  <strong>Take home salary or Wage:</strong>  
  <%= @income.income1 %>
</p>
class Income < ActiveRecord::Base
attr_accessor :first_name, :last_name, :date_of_birth, :income1, :income2, :income3, :income4, :income5, :income6, :income7, :income8, :income9, :income10 
end
Rails.application.routes.draw do
 resources :incomes
 root 'incomes#new' 
end