Tag: 链接到

form_for通过2个链接提交,当我回到控制器中时,如何告诉我使用了哪个?

我将表单放在一起,但出于设计原因,表单必须通过链接提交。 我发现了如何执行: = link_to_function “Next >>”, “$(this).up(‘form’).submit()” 这样做,我可以用这个创建许多链接没问题。 但是我不知道如何区分使用哪个链接将我带回控制器? 我需要根据链接略有不同…… 任何的想法 ? 我试图嵌入一些javascript等,但我无法弄明白。 谢谢, 亚历克斯

link_to更新(没有表格)

我想要一个更新资源的链接,而不使用HTML表单。 路线: resources :users do resource :profile, :controller=>”profiles” resources :friends end 耙路线: user_friend GET /users/:user_id/friends/:id(.:format){:action=>”show”, :controller=>”friends”} PUT /users/:user_id/friends/:id(.:format){:action=>”update”, :controller=>”friends”} 我想通过简单的链接使用put来更新朋友,如下所示: ‘put’)%> 但是当Rails遇到这个链接时,他试图进入节目动作。 问题是:这样做的正确链接是什么?

使用rails中的link_to提交表单

我正在尝试使用link_to提交表单,如下所示: ‘/post/action’, :method=> ‘post’, :html => {:id=>’form_id’} ) do |f| %> …. “document.getElementById(‘form_id’).submit()” %> …. 但它没有发布表单,它只是将我的表单重定向到指定的URL。 有谁知道如何做到这一点?

Rails’link_to’立即下载图像,而不是在浏览器中打开它

我有一个link_to Rails助手,可以在点击时下载壁纸。 但是图像正在浏览器中加载而不是立即下载。 但同时我有一个link_to Rails帮助程序,可以下载.exe格式的屏幕保护程序,但这里的工作方式是:立即下载文件。 我应该添加或执行哪些操作,以便图像不会在浏览器中打开,而是立即下载? 谢谢!

link_to:action =>’create’转到索引而不是’create’

我正在构建一个相当简单的配方应用程序来学习RoR,我试图通过单击链接而不是通过表单来允许用户保存配方,因此我通过link_to连接user_recipe控制器的“创建”function。 不幸的是,由于某种原因,link_to正在调用索引函数而不是create。 我把link_to写成了 ‘create’,: recipe_id => @recipe%> 此链接位于user_recipes / index.html.erb上,并且正在调用同一控制器的“create”function。 如果我包含:controller,它似乎没有什么区别。 控制器看起来像这样 def指数 @recipe = params [:recipe_id] @user_recipes = UserRecipes.all#更改以查找db中的多个用户 respond_to do | format | format.html #index.html.erb format.xml {render:xml => @recipes} 结束 结束 def创建 @user_recipe = UserRecipe.new @ user_recipe.recipe_id = params [:recipe_id] @ user_recipe.user_id = current_user respond_to do | format | if @ menu_recipe.save format.html […]

Ruby on Rails:如何使用link_to将参数从视图传递到控制器,而不在URL中显示参数

我目前在View中使用link_to帮助程序将title,author,image_url和isbn等参数传递给控制器 title, :author => authors, :image_url=>image, :image_url_s=>image_s, :isbn=>isbn, :isbn13=>isbn13 ) %> 然后,Controller将参数分配给稍后在View中的表单使用的对象(在new.html.erb中) def new @item = Item.new @item.title = params[:title] @item.author = params[:author] @item.image_url = params[:image_url] @item.image_url_s = params[:image_url_s] @item.isbn = params[:isbn] @item.isbn13 = params[:isbn13] respond_to do |format| format.html # new.html.erb format.xml { render :xml => @item } end end 然后将调用new.html.erb。 这一切都正常,但url显示所有参数 http://localhost:3000/items/new?author=Michael+Harvey&image_url=http://sofzh.miximages.com/ruby-on-rails/51vt1uVjvLL._SL160_.jpg&image_url_s=http://sofzh.miximages.com/ruby-on-rails/51vt1uVjvLL._SL75_.jpg&isbn13=9780307272508&isbn=0307272508&title=The+Third+Rail 有什么办法可以让参数不显示在URL上吗?

Rails link_to具有内联样式

我必须在不使用CSS类的情况下更改link_to标记颜色,我该怎么办? 我尝试过像 ‘color:#FFFFFF;’, :class => “css_class”} %> 但它不适用于ruby 1.9.2和rails 3.1

ruby on rails link_to图片

我面临以下问题:我有一个非常小的图库,图像文件位于以下目录中 app/assets/images/locale/thumbs/ app/assets/images/locale/big/ 我必须创建一个超链接,作为内容有一个拇指图像和目标 – 它来自app / assets / images / locale / big /文件夹的更大版本: 我是通过这种方式做到的 = link_to(image_tag(“locale/thumbs/001.jpg”), “locale/big/spizzicaluna001.jpg”) 实际上我已经为link_to的第二个参数尝试了很多变种但是没有成功 – 找不到更大的文件。 如何解决这个问题?

将参数传递给link_to方法

如何使用link_to方法通过MVC传递参数? 视图: 如何使用link_to方法来利用remove_tag操作? issues_controller.rb def remove_tag(parameter) @issue.remove_it(parameter) end issue.rb def remove_it(parameter) self.users.delete(User.find(parameter)) end

我的rails 4应用程序上的每个link_to都被调用两次

我正在使用我的Rails 4应用程序遇到一些不寻常的行为。 每次我点击我的视图中的link_to,我的控制器动作被调用两次。 例如: 在我的root_url我对root_url进行了这个标准调用: “logout-button”) %> 当我单击此链接时,我的控制台显示以下输出: Started GET “/users/profile” for 127.0.0.1 at 2013-11-25 20:45:53 -0200 Processing by Users::SessionsController#profile as HTML User Load (0.7ms) SELECT “users”.* FROM “users” WHERE “users”.”id” = 45 ORDER BY “users”.”id” ASC LIMIT 1 InvestorProfile Load (0.5ms) SELECT “investor_profiles”.* FROM “investor_profiles” WHERE “investor_profiles”.”user_id” = $1 ORDER BY “investor_profiles”.”id” ASC LIMIT […]