PostsController中的SyntaxError#rails中的ruby中的索引

时间:2014-01-20 05:20:03

标签: ruby-on-rails ruby

我刚开始在铁轨上学习红宝石。我按照http://edgeguides.rubyonrails.org/getting_started.html上的指南进行了操作。

posts_controller.rb文件包含以下代码

class PostsController < ApplicationController

def create
  @post = Post.new(post_params)

  if @post.save
    redirect_to @post
  else
    render 'new'
  end
end

def show
  @post = Post.find(params[:id])
end

def index
  @posts = Post.all
end

def edit
  @post = Post.find(params[:id])
end

def update
  @post = Post.find(params[:id])

  if @post.update(post_params)
    redirect_to @post
  else
    render 'edit'
  end
end

def destroy
  @post = Post.find(params[:id])
  @post.destroy

  redirect_to posts_path
end

private
  def post_params
    params.require(:post).permit(:title, :text)
  end

我的app/views/posts/new.html.erb文件包含

<h1>New post</h1>
<%= form_for :post, url: posts_path do |f| %>
<% if @post.errors.any? %>
  <div id="error_explanation">
    <h2><%= pluralize(@post.errors.count, "error") %> prohibited
      this post from being saved:</h2>
    <ul>
    <% @post.errors.full_messages.each do |msg| %>
      <li><%= msg %></li>
    <% end %>
    </ul>
  </div>
  <% end %>
  <p>
    <%= f.label :title %><br>
    <%= f.text_field :title %>
  </p>

  <p>
    <%= f.label :text %><br>
    <%= f.text_area :text %>
  </p>

  <p>
    <%= f.submit %>
  </p>
<% end %>
<%= form_for :post do |f| %>
  ...
<% end %>

<%= render 'form' %>

<%= link_to 'Back', posts_path %>

此外app/views/posts/edit.html.erb包含

<h1>Edit post</h1>

<%= form_for :post, url: post_path(@post), method: :patch do |f| %>
  <% if @post.errors.any? %>
  <div id="error_explanation">
    <h2><%= pluralize(@post.errors.count, "error") %> prohibited
      this post from being saved:</h2>
    <ul>
    <% @post.errors.full_messages.each do |msg| %>
      <li><%= msg %></li>
    <% end %>
    </ul>
  </div>
  <% end %>
  <p>
    <%= f.label :title %><br>
    <%= f.text_field :title %>
  </p>

  <p>
    <%= f.label :text %><br>
    <%= f.text_area :text %>
  </p>

  <p>
    <%= f.submit %>
  </p>

<% end %>

<%= render 'form' %>

<%= link_to 'Back', posts_path %>

SyntaxError in PostsController#index
C:/Users/punitha/blog/app/controllers/posts_controller.rb:50: syntax error, unexpected end-of-input, expecting keyword_end

Rails.root: C:/Users/punitha/blog

Application Trace | Framework Trace | Full Trace
Request

Parameters:

None
Toggle session dump
Toggle env dump
Response

Headers:

none.

1 个答案:

答案 0 :(得分:1)

end

的最底部看起来似乎缺少posts_controller.rb