如果我有以下 JavaScript 代码
var myVar = 0;
function setNewValforVar(newValue){
myVar = newValue;
}
Run Code Online (Sandbox Code Playgroud)
我正在调用setNewValforVar功能n时间
因此,当我单击链接时,它会将myVar值发送到远程链接中的控制器操作,例如
<%=link_to "My Link",{:action=>"myAction"},:data=>''sval='+myVar',:remote=>true%>
Run Code Online (Sandbox Code Playgroud)
我 Rails 2.3.x 我会这样做
<%=link_to_remote "My Link",:url=>{:action=>"myAction"},:with=>"'sval='+myVar"%>
Run Code Online (Sandbox Code Playgroud)
我在控制器的操作中得到了这个
params["myVar"]
Run Code Online (Sandbox Code Playgroud)
我如何使用link_to助手在 Rails 3 上执行此操作?
考虑以下 link_to 示例:
link_to "Personal Website", @user.website
我如何保护它免受 XSS 攻击。用户表在外部数据库中,所以我不能相信它。我尝试过使用 sanitize 和 h 的不同方法,但是当我在本地数据库用户网站中替换javascript:alert('XSS')为 时,当我单击链接时,javascript 仍在执行。
提前致谢,
我希望用户能够从我在控制器中设置的方法下载文件。此外,当用户下载文件时,我不希望 URL 在我的浏览器中更改。我设置了这个链接
<%= link_to image_tag("cc_icon.png"), scenario_download_cc_path(subscription.scenario), target: '_blank' %>
Run Code Online (Sandbox Code Playgroud)
问题是,当生成新选项卡以生成下载时,屏幕会闪烁。这在视觉上看起来不吸引人。我已经看到其他网站,您单击链接后会立即开始下载某些内容。我怎么做?
编辑: 这是链接调用的函数
def download_cc
scenario = Scenario.find(params[:scenario_id])
send_data scenario.cc_data, filename: "#{scenario.title}.imscc", type: 'application/zip', :disposition => 'attachment'
end
Run Code Online (Sandbox Code Playgroud) <%= link_to "Destroy", article_path(@article), data: {
turbo_method: :delete,
turbo_confirm: "Are you sure?"
} %>
Run Code Online (Sandbox Code Playgroud)
这是 Ruby on Rails 官方网站上列出的删除 Active Record 的简单方法。我有和他们一样的控制器方法。这不会删除,也不会确认。我发现其他方法可以成功删除,但没有一个可以确认。我想了解为什么这不会删除,以及如何确认。
我有两个链接:
<%= link_to("Edit", edit_product_path(product.id)) %>
<%= link_to("Delete", product, :method => :delete) %>
Run Code Online (Sandbox Code Playgroud)
生成的链接是:
<a href="/products/81/edit">Edit</a>
<a href="/products/81" data-method="delete" rel="nofollow">Delete</a>
Run Code Online (Sandbox Code Playgroud)
单击同时打开Edit和打开时Delete,将GET使用该方法.
Rails如何决定使用哪种方法?
链接中的含义data-method="delete"和rel="nofollow"含义是什么Delete?
ruby-on-rails http-verbs http-method link-to ruby-on-rails-3
自从我开始深入挖掘形式,联想,哈希,符号以来已经差不多一个星期......但似乎没有你的帮助我无法解决这个难题.
我正在开展一个展示不同画廊内容的项目.基本思想是当用户看到画廊的名称(名称是链接)时能够点击所选择的名称.然后显示属于此库的所有图像.在底部应该有一个链接"在此库中添加图像".
我的模特:
class Gallery < ActiveRecord::Base
attr_accessible :name
has_many :pictures
end
class Picture < ActiveRecord::Base
attr_accessible :image
belongs_to :gallery
end
Run Code Online (Sandbox Code Playgroud)
我在gallery_id上为'pictures'表创建了索引.
我的大问题出现在这里,如何将gallery_id传递给控制器的动作'new'.正如我在"使用Rails进行敏捷Web开发"中看到的那样,它可能是:
<%= link_to'在这里添加图片...',new_picture_path(:gallery_id => @ gallery.id)%>
在这种情况下似乎是foreign_key:gallery_id在浏览器的URL栏中公开.第二个问题是:gallery_id可用于控制器的"新"功能,但"创建"功能"消失"(导致错误"无法找到没有ID的图库").当我在_form中为图片添加隐藏字段时,问题就消失了,在我的情况下:
<%= form_for(@picture) do |f| %>
<div class="field">
<%= f.hidden_field :gallery_id , :value=>params[:gallery_id] %>
<%= f.label :image %><br />
<%= f.file_field :image %>
</div>
<div class="actions">
<%= f.submit "Create" %>
</div>
<% end %>
Run Code Online (Sandbox Code Playgroud)
以下是我在'pictures'控制器中的定义:
def new
@gallery=Gallery.find(params[:gallery_id])
@picture=@gallery.pictures.build
end
def create
@gallery = Gallery.find(params[:gallery_id])
@picture = @gallery.pictures.new(params[:picture])
if @picture.save
redirect_to(@picture, :notice …Run Code Online (Sandbox Code Playgroud) 如何使用link_to方法通过MVC传递参数?
视图:
<%= link_to "Remove Tag", remove_tag_issue_path(issue)%>
Run Code Online (Sandbox Code Playgroud)
如何使用link_to方法来利用remove_tag操作?
issues_controller.rb
def remove_tag(parameter)
@issue.remove_it(parameter)
end
Run Code Online (Sandbox Code Playgroud)
issue.rb
def remove_it(parameter)
self.users.delete(User.find(parameter))
end
Run Code Online (Sandbox Code Playgroud) 我希望用户在我的Rails应用程序中能够在他们的个人资料中分享他们个人网站的链接.很简单,我有一个名为的列website和一个文本字段,他们可以填写它以使其工作.
但是,当我在视图中显示这个问题时.如果我使用link_to帮助者,那么包括的人http://是否确定该URL是否有效.但是,如果我自动预先添加,http://那么对于将DID放入其网址的用户,我会获得两次.
我确信这是一个相当普遍的问题,但我找不到任何好的博客文章或解决它的SO问题.
我的问题是:您如何处理应用中用户的URL输入?您会建议什么是最方便用户友好的方式来标准化最终存储在数据库中的URL?
谢谢!
我有一个导航按钮,通过Lightbox 2加载一个新页面(create.html.erb).
create.html.erb放在公用文件夹中.
一切都很好,但嵌入的红宝石不起作用.
<div class="addButtons">
<div id="addPromotion">
Add a Promotion
<div id="promotionInfo">
<%= render 'shared/promotion_form'%>
</div>
</div>
<div id="createBoard">
Create a Board
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
页面将其加载为文本而不是实际呈现.我试过做一个链接,它工作正常.
如何在rails link_to中插入HTML实体?
例如✭会给你一个明星字符,如何在引号中插入?
例如,
<%= link_to " ✭ Home", root_path %>
Run Code Online (Sandbox Code Playgroud)
谢谢!
link-to ×10
ruby ×2
associations ×1
download ×1
erb ×1
file ×1
forms ×1
href ×1
html ×1
http-method ×1
http-verbs ×1
lightbox2 ×1
parameters ×1
security ×1
url ×1
xss ×1