按按钮并添加到标题
我有一篇文章,它有一个标题。我希望用户能够按下一个按钮,然后在标题后面放置完成的单词,但我不确定如何做到这一点。
我的帖子视图看起来像
<% div_for post do %>
<strong><%= link_to_unless_current h(post.title), post %></strong> - <%= link_to post.user.name, post.user %>
<%= simple_format h(post.body) %>
<% end %>
我觉得我可能需要一个 if 语句,说明如果单击了视图的原始代码加上“已完成”的其他原始代码,但我不确定如何在按钮中使用此逻辑以及如何描述此逻辑。我仍然是一个菜鸟,所以如果这个问题过于简单,我很抱歉。
我想要做的是有一个标记为已完成的按钮,将工作完成添加到标题的末尾。
这是我的显示视图,
<%= render :partial => @post %>
<% if current_user?(@post.user) %>
<p>
<%= link_to 'Edit', edit_post_path(@post)%>
<%= link_to 'Delete', @post, :method => :delete, :confirm => "Are you sure?" %>
</p>
<% else %>
<% end %>
<h2>Comments</h2>
<div id="comments">
<%= render :partial => @post.comments %>
</div>
<%= form_for [@post, Comment.new] do |f| %>
<p>
<%= f.label :body, "New Comment" %><br />
<%= f.text_area :body %>
</p>
<p><%= f.submit "Add Comment" %></p>
<% end %>
我的主要问题中显示的视图是每个单独帖子的视图,所以基本上我想在 <%= link_to_unless_current h(post.title), post %> 前面添加完成当我按下按钮时的代码块,然后它应该显示完成的单词和原始标题
I have a post and it has a title. I want the user to be able to press a button and then after the title the word completed is placed in but I'm not sure how I would do this.
my post view looks like
<% div_for post do %>
<strong><%= link_to_unless_current h(post.title), post %></strong> - <%= link_to post.user.name, post.user %>
<%= simple_format h(post.body) %>
<% end %>
I feel like I may need an if statement saying if clicked original code for the view plus "completed" else original code but I'm not sure how I would use this logic in a button and how to describe this logic. I'm still a noob so I'm sorry if this question is overly simple.
What I want to do is have a button labeled completed that adds the work complete onto the end of the title.
this is my show view
<%= render :partial => @post %>
<% if current_user?(@post.user) %>
<p>
<%= link_to 'Edit', edit_post_path(@post)%>
<%= link_to 'Delete', @post, :method => :delete, :confirm => "Are you sure?" %>
</p>
<% else %>
<% end %>
<h2>Comments</h2>
<div id="comments">
<%= render :partial => @post.comments %>
</div>
<%= form_for [@post, Comment.new] do |f| %>
<p>
<%= f.label :body, "New Comment" %><br />
<%= f.text_area :body %>
</p>
<p><%= f.submit "Add Comment" %></p>
<% end %>
the view in shown in my main question is the view for each individual post so basically I want to add completed in front of <%= link_to_unless_current h(post.title), post %> that block of code when I press the button and then it should display the word completed and the original title
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不明白你的想法,如果点击标题时到底会发生什么,但是如果你想在我们的 html 网站中即时更改内容,你需要 JS 或 ajax 来处理这个...
你可以发送更多示例代码吗?指定应该发生什么或标题应该放在哪里?
Im not getting your idea if what exactly shoul happen when clicking on the title, but if u want to change stuff on the fly in our html site, u need JS or ajax to handle this...
Could u please send more example code or specify what should happen or where the title should be placed?