English 中文(简体)
我如何去除与法案的标签联系——As_Taggable_ 铁路?
原标题:How do I create remove tag links with Acts_As_Taggable_On in Rails?

I m 采用“As_Taggable_ On。

在每个项目中增加标记(如我的情况类型/类型)是巨大的。 在Im st脚石的地方,如何利用法律消除个人标签——As_Taggable_ 关于我想要能够点击每个标的旁边的X文本链接(见链接),以便把标子从这些项目的类型中删除。

我搜索了这些文件,并找到了一条大致如下的方法:

project.type_list.remove("your tag")

但我需要帮助的是,如何将清除方法称作具体主角,特别是因为所有东西都正在与......做ach。

My controller and model code is pretty minimal and standard - based on Act_As_Taggable_On docs. Here is my view code for generating the layout above:

<h1><%= @title %></h1>
<div class="column-left">
  <% @projects.each do |project| %>
    <div class="p_wrapper">

      <table>
        <tr>
          <td><div class="project p_name"><%= project.name %></div></td>
          <td><div class="p_link"><%= link_to  Edit , edit_project_path(project) %></div></td>
          <td><div class="p_link"><%= link_to  Nuke , project, :confirm =>  Are you sure? , :method => :delete %></div></td>
        </tr>
      </table>

      <table>
        <tr>
          <td>
              <% project.type_list.each do |tag|%>
                <div class="p_tag">
                <%= tag %> 
                <%= link_to "x", # %> <!-- THIS IS THE PART I M STUCK ON -->
              </div> 
              <% end %>
            </td>
        </tr>
      </table>

      <table>
        <tr>
            <td>
              <%= form_for(project) do |f| %>
              <%= f.text_field :inject_tags %>  
              <%= f.submit "Add Tag" %>
              <% end %>
            </td>
        </tr>
      </table>

    </div>

  <% end %>

  <br />

  <%= link_to  Add new project , new_project_path %>
</div>

谁能向我指出正确的方向? 我正确地执行这一规定,以便能够实际消除所描述的标签?

感谢gu!

最佳回答

根据“Vapire s”所建议的代码,最终确定了一种可行的解决办法。 只是一些小小its子 to着观点、路线和控制器。 让我知道,你在这里是否看到任何麻烦——仍然试图很好地掌握Ruby/Rails,因此欢迎所有建议/设想。

The updated test site is at project-list.heroku.com.

更新项目控制器,以找到当前项目,删除:通过路线从指数角度通过:

def remove_tag
  @project = Project.find(params[:id])
  @project.type_list.remove(params[:tag])
  @project.save
  redirect_to projects_path, :flash => { :success => "Updated - tag nuked."}
end

更新路线:

resources :projects
match  projects/:id/remove_tag/:tag  =>  projects#remove_tag 

更新了“至x代码”的链接,以便通过上述最新路线:

<% project.type_list.each do |tag|%>
  <div class="p_tag">
    <%= tag %> 
    <%= link_to  x , {:action => "remove_tag", :id => project.id, :tag => tag, 
    :controller => "projects"} %>
  </div> 
<% end %>

对我来说,这显然是新的理由,如果你有不同的/更好的办法处理这一问题,请让我知道! 还感谢您的帮助!

问题回答

我只想给项目控制者增加新的方法,例如:

def remove_tag
  Project.find(params[:id]).type_list.remove(params[:tag])
end

和在座标

resources :projects do
  member do
    put  remove_tag , :as => :remove_tag
  end
end

你的看法

<%= link_to  x , remove_tag_project_path(project), :tag => tag, :method => :put %>

当然,你应该增加一些卫生设施,但应该这样做。





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签