如何使用RoR删除SyntaxError

时间:2015-03-02 10:25:59

标签: ruby-on-rails ruby

我遇到一个语法错误,在我处理Rails环境时无法将其删除。请阅读以下错误并检查我的代码,如下所述。

错误:

SyntaxError in Homes#managebooks

Showing C:/Site/library_management1/app/views/homes/managebooks.html.erb where line #106 raised:

C:/Site/library_management1/app/views/homes/managebooks.html.erb:106: syntax error, unexpected ':', expecting tASSOC
...remove_path(:id => @books.id) :confirm => "Are you sure to r...

我的代码如下。

的观点/舍/ managebooks.html.erb

<% if admin_signed_in? %>
<div class="bar">
  Logged in as <strong><%= current_admin.email %></strong>.
  <%= link_to 'Edit profile', edit_admin_registration_path, :class => 'navbar-link' %> |
  <%= link_to "Logout", destroy_admin_session_path, method: :delete, :class => 'navbar-link'  %>
</div>
<% else %>
  <%= link_to "Sign up", new_admin_registration_path, :class => 'navbar-link'  %> |
  <%= link_to "Login", new_admin_session_path, :class => 'navbar-link'  %>
<% end %>
<div class="big-container">
    <% if flash[:color]== "valid" %>
        <div class="valid_notice">
            <p><%= flash[:notice]%></p>
        </div>
    <% elsif flash[:color]== "invalid"%>
        <div class="invalid_notice">
            <p><%=flash[:notice]%></p>
        </div>
    <%else%>
        <div class="notice">
            <p><%=flash[:notice]%></p>
        </div>
    <%end%>
<div class="admin-image">
 <div class="bpaddingdiv1"><img src="/assets/admin.png" border="0" name="admin" /></div>
</div>
<div class="borderlightgreen"></div>
<div class="admin-name">
<div class="tpaddingdiv2 textaligncenterdiv"><img src="/assets/adminpanel.png" border="0" name="admin" /></div>
</div>
<div class="leftside">
<div id="leftsidebtn">
 <ul>
<li><a href="/homes/managebooks">Manage Books</a></li>
<li><a href="#" >Manage Pages</a></li>
<li><a href="#" >Manage Header Banner</a></li>
<li><a href="#" >Brand</a></li>
 </ul>  
</div>
</div>
<div class="middlebox">
<center>
    <%= form_for :books,:url => {:action => "savebooks"} do |f| %>
    <fieldset>
         <p>
            <label for="name">Book name</label>
            <%= f.text_field :book_name,placeholder:"enter book name" %>
         </p>

         <p>
            <label for="tel">Book title</label>
            <%= f.text_field :book_title,placeholder:"enter book title" %>
         </p>

         <p>
            <label for="email">Author Name</label>
           <%= f.text_field :author_name,placeholder:"enter book author name" %>
         </p>

         <p>
            <label for="password">publisher Name</label>
            <%= f.text_field :publisher_name,placeholder:"enter book publisher name" %>
         </p>
         <p>
            <label for="password"> Edition</label>
           <%= f.text_field :edition,placeholder:"enter book edition" %>
         </p>
         <p>
            <label for="password">Pages</label>
           <%= f.text_field :pages,placeholder:"enter book pages" %>
         </p>
         <p>
            <label for="password"> Date of pursase</label>
            <%= f.date_select :date_of_purchase %>
         </p>

         <p>
            <%= f.submit "SUBMIT" %>
         </p>
    </fieldset>
 <% end %>
</center>
<% if params[:id] %>
<table>
<tr>
<th>Book name</th>
<th>Book title</th>
<th>Author Name</th>
<th>publisher Name </th>
<th>Edition</th>
<th>Pages</th>
<th>Date of pursase</th>
<th>Status</th>
<th>Action</th>
</tr>
<tr>
    <td><%= @books.book_name %></td>
    <td><%= @books.book_title %></td>
    <td><%= @books.author_name %></td>
    <td><%= @books.publisher_name %></td>
    <td><%= @books.edition %></td>
    <td><%= @books.pages %></td>
    <td><%= @books.date_of_purchase  %></td>
    <td><%= image_tag("/assets/1.png") %></td>
    <td><%= link_to image_tag("/assets/logout.png", :alt => "image", :width => 40, :height => 40, :title => "Delete item"),:method => :delete ,homes_remove_path(:id => @books.id) ,:confirm => "Are you sure to remove this?" %></td>
    </tr>
</table>
<% end  %>
</div>
</div>

请尝试帮我删除此语法错误。我正在使用rails版本3.2.19和ruby版本1.9.3.Thanks提前。

2 个答案:

答案 0 :(得分:1)

这一行不正确,网址需要出现在选项前面:

<%= link_to(
      image_tag(
        "/assets/logout.png", 
        :alt => "image", :width => 40, :height => 40, :title => "Delete item"
      ),
      homes_remove_path(:id => @books.id),
      :method => :delete, :confirm => "Are you sure to remove this?") %>

答案 1 :(得分:1)

错误告诉您在此行中:confirm之前需要逗号:

`remove_path(:id => @books.id) :confirm => "Are you sure to r...`

当它需要逗号或方法调用结束以及错误意味着什么时,它会点击: