link-to

Syntax for link_to with block in rails3 with :remote=>true and including :class and :id

戏子无情 提交于 2019-12-06 01:45:39
For the love of god, I've been banging my head on this for hours. Using rails3 rc, 1.9.2. I'm trying to create a link_to that submits an ajax request, with parameters, a class and id, and needs a block so I can insert a span tag around the name. Documentation is of absolutely zero help, as are numerous google searches. Here's what I've got so far: <%= link_to( :url=>{ :controller => 'themes', :action => 'remove_tag', :entity_id => entity_id, :theme_id => theme_id, :entity => entity, :element_id => element_id, :parent_id=>parent_id }, :remote => true, :id => "theme-tag-#{entity}-#{entity_id}",

How do you pass multiple arguments to nested route paths in Rails?

折月煮酒 提交于 2019-12-05 09:58:09
I am new to Rails and normally set up a link_to helper for a normal unnested route like so: link_to "Delete", article_path(article.id), method: :delete, data: {confirm: "Are you sure?"} However I am learning about nested routes and it seems I need to provide the path with two arguments for example: link_to "(Delete)", article_comments_path(comment.article_id, comment.id), method: :delete, data:{comfirm: 'Are you sure?'} However this does not seem to work. I have seen that you can format the link_to like this: link_to 'Destroy Comment', [comment.article, comment], method: :delete, data: {

rails 4 with link_to and method post with strong parameters

一曲冷凌霜 提交于 2019-12-05 09:46:27
I'm stuck in a problem which can't be that complicated, but I'm just not getting things right. Assuming I've got two Models: class Notification < ActiveRecord::Base belongs_to :device validates :number, presence: true end and class Device < ActiveRecord::Base belongs_to :user has_many :notifications, :dependent => :destroy //rest omitted for brevity end with nested routes like so: resources :devices do resources :notifications end and a notifications controller like so: class NotificationsController < ApplicationController before_filter :authenticate_user! before_action :set_device, :only => [

Ruby on Rails link_to internal id

左心房为你撑大大i 提交于 2019-12-05 08:04:25
How do i use a link_to inorder to go to a specific (html) ID on a page normally if i wanted to go to the "whatever_id" on a page i could use <a href="http://www.example.com/index/mypage#whatever_id>Click Here</a> but i would like to use my link_to <%= link_to "click here" , {:action => "mypage", :controller => "index" }, :id => "#whatever_id"%> helper methods. Does anyone know how to do this? Is it possible? Rails 2.3.4 link_to can add anchors to a URL. From the documentation , link_to "Comment wall", profile_path(@profile, :anchor => "wall") # => <a href="/profiles/1#wall">Comment wall</a> In

clean way to make the “confirm” conditional in rails 4

好久不见. 提交于 2019-12-05 06:51:01
I have a link_to on my rails4 page which uses slim syntax. The following link_to link_to exports_path, data: { confirm: "Are you sure?" } is now required to only show the confirm message upon a certain condition. How do we make this happen in rails4? I tried: link_to exports_path, data: { confirm: result_count > 50 ? "Are you sure?" : nil } which seems to always show the confirm regardless of the condition.. How about link_to exports_path, data: (result_count > 50 ? { confirm: "Are you sure?"} : nil) you can also have the conditional for setting the confirm message or nil inside the data hash

Rails: How can I show a block with or without a link based on a condition (link_to_if)

≯℡__Kan透↙ 提交于 2019-12-05 04:39:53
I have a complex block of tags ( <h3> , <p> , ...) that I want to render with a link or without a link around it based on a condition. I know about link_to_if that works like that: <% link_to_if condition, name, path %> if the condition is false only the name will be rendered. And I know about the link_to with &block : <% link_to path do %> [complex content] <% end %> I want a combination of both. A link_to_if statement that accepts a &block , so that the block will be rendered without a link around it, if the condition is false . Unfortunately the link_to_if statement with a &block works not

Rails 3.2.2 with Twitter Bootstrap Tabs Ajax not working

只谈情不闲聊 提交于 2019-12-05 04:26:48
问题 I'm on my second app with Rails and I want to get ajax working. I'm also using the tabs from bootstrap 2. There are two variations of the tabs for bootstrap that I found, one gives you the tabs and you can put the content of those tabs into DIVs, the other is basically each tab you are able to use a link. I opted for the latter so that I could Ajaxify the links. The basic idea is that my apps home page has tabs across the top such as: Home, Inventory, Tasks, etc...and when you click the tab

Ruby on Rails: link-to using post method but parameters are in the URL

 ̄綄美尐妖づ 提交于 2019-12-05 00:24:58
I'm using link_to 'My link', path(:arg1 => session[:arg1], :arg2 => session[:arg2],:arg3 => anyobject.id), :method => :post but the HTML link being generated includes (arg1,arg2,arg3) as URL query parameters. How can remove them? Did I miss something in the documentation? A link_to will always put the arguments into the query string as it is creating a get-style HTML link - even if you put :method => :post that just appends an extra ("special") argument _method . What I think you really want is a button_to link - which will make it into a sort of form-post. It works the same, but it says

rails 3 render partial with params

放肆的年华 提交于 2019-12-05 00:21:12
I'm having a problem passing some parameters to a partial. No matter what I've tried the params don't pass when the partial is rendered. I am using a jquery tabbed layout, and each tab displays work orders in a particular status and also based on a range of dates. I am using the params :sort_filter and :status_filter to accomplish this. My original code is here, but I want to change this to render partials in the link_to's instead of the way it's listed here: <ul> <li><%= link_to "Active", work_orders_path(params.merge({:status_filter => "A", :sort_filter => params[:sort_filter]})) %></li> <li

Ruby on Rails link_to With put Method

老子叫甜甜 提交于 2019-12-04 22:24:09
I'm new to Rails, and I'm trying to use the link_to helper to create a link that issues a PUT request instead of a GET request. Specifically, I'm trying to create a link that activates a user's account in my app from the admin's panel. I'm using Rails 3.0.5. My routes.rb file has: match '/admin/users/:id/activate' => 'admin#activate_user', :action => :activate_user, :via => :put My view has: link_to 'Activate', :action => :activate_user, :id => user.id, :method => :put However this generates the URL (for example) /admin/users/7/activate?method=put with the source code <a href="/admin/users/7