link-to

Rails 3.1.3 using anchor attribute with link_to tag from posts/index to posts/show/id not working

心已入冬 提交于 2019-12-12 08:48:45
问题 I am using a link_to tag on my posts/index view and want to link it to my posts/show/id view with an anchor that makes it scroll down to the comments form. For some reason I can't get the anchor to work. Here is my code: In posts/index <%= link_to 'Add a Comment', post, :anchor => 'comment_form' %> This fails to append the # sign to the end of the link, so it is just localhost:3000/posts/id. I have also tried many variations for link_to, including: <%= link_to 'Add a Comment', post(:anchor =>

Button_to uses POST Link_to uses GET, why? ROR

こ雲淡風輕ζ 提交于 2019-12-12 08:29:48
问题 I've ran into a ror problem using the link_to. Why does my link to use the GET method and my button_to use the POST method, after I specified my "method"=>"post" within the link_to parameters? View: <%= button_to "pdf", :action => 'getquote' %> <%= link_to 'pdf', {:controller => 'inventories', :action => 'getquote', :method => :post } %> Controller Method: def getquote @cart = find_cart respond_to do |format| format.pdf end end Terminal Output (Button/Link, respectively): Processing

Rails link_to pass :id from show to another controller action

我的梦境 提交于 2019-12-12 04:20:03
问题 I'm viewing 1 product in show.html.erb and there's a link below that says "View other products from this company". This link_to connects to another non-restful action in same controller which retrieves from DB other products of same company as was shown in show.html.erb. Can link_to pass the :id of the current product in show to action it's rendering? I'm new to rails and please let me know if question is not making sense. I'm not sure if routes need to be defined as well. Thanks. products

No Route Matches: Missing required [:id] when using nested namespace

别说谁变了你拦得住时间么 提交于 2019-12-12 01:56:11
问题 this is my routes.rb filled with Rails.application.routes.draw do namespace :main, path: ':master_url' do root 'sites#index' namespace :dashboard do root 'dashboards#index' #get 'masters/index' resources :masters end get "/:action" => 'sites#:action' end root 'main/sites#index' end this is command rake routes main_root GET /:master_url(.:format) main/sites#index main_dashboard_root GET /:master_url/dashboard(.:format) main/dashboard/dashboards#index main_dashboard_masters GET /:master_url

How can I link to a nested child from outside the parent element in Rails 4?

大憨熊 提交于 2019-12-11 20:20:01
问题 Ok, my situation. I have a nested resource of resources :projects do resources :campaigns end I want to make a view with controller with resources :portfolios I want to make a <% link_to %> that listed all campaigns which I can do, but when I try to route the path i can't make it link to a campaign. Example: in my portfolios/view/index.html.erb <% @projects.each do |p| %> <% p.campaigns.each do |c| %> <div class="container" > <div> <%= link_to ( image_tag c.image_camp.url(:thumb)), p %> </div

Link_to remote => true causing strange routing problems, Rails 3

冷暖自知 提交于 2019-12-11 19:58:56
问题 I am having some problems with link_to remote sending a post to another controller... The result are not quite what I expect.. I have this in node_content.html.erb: <% @node.videos.each do |vid| %> <div id="vid_vid"><%= link_to image_tag("http://img.youtube.com/vi/#{vid.content}/1.jpg"), :controller => 'videos', :action => "iframize", :video_id => vid.id, :method => :post, :remote => true %></div> <% end %> And I have this in videos_controller: def iframize @video = Video.find(params[:video

Simple routing in Rails

妖精的绣舞 提交于 2019-12-11 14:36:34
问题 I'm trying to destroy a link from a User Show view. So from /users/1 , I want to access destroy action in teacher_student_links controller. The first attempt: <%= link_to 'destroy', :controller => "teacher_student_links", :action => "destroy", :id => @user.id %> This fails because it routes to "show" action in the specified controller. So first question: why does it point to the "show" action instead of "destroy?" I tried to enclose the above with parenthesis, and got a meaningless error as

What is causing this undefined method `model_name' for Hash:Class

独自空忆成欢 提交于 2019-12-11 14:32:40
问题 I am trying to implement a link in rails that will point to a certain url with a delete: method and with some params in the url, what I am trying is this: <%= link_to "Remove", [:remove_country, :admin, @species, my_param: country.id ], method: :delete %> Note the my_param: country.id I am trying to pass in. This gives me the result: undefined method `model_name' for Hash:Class due to the hash in the params. Unfortunately I need that there as I am trying to pass an extra param into the url

Paths showing up in link_to

我怕爱的太早我们不能终老 提交于 2019-12-11 09:28:16
问题 I am new to rails having just completed rails for zombies (railsforzombies.org) and am trying to build my first app (a blog). I have scaffolded a basic structure and made changes including changing routes adding partials and other improvements to the view as well as installing the Blueprint css framework. The problem I'm having is that all of my links (created with link_to) end up looking like this: test post(/post/1) Where the path to the link is printed after the link itself. However, I

Rails link_to: Do something after confirmation

百般思念 提交于 2019-12-10 13:08:16
问题 I'm trying to execute a save action via AJAX using link_to : <%= link_to 'Save', image_path(image), method: :patch, data:{ confirm: 'Save image?', remote: true } %> I want the link to be replaced with <span>Saving...</span> on confirmation, but can't figure out a clean way to do it. Problems with existing solutions: disable_with: If I add :disable_with => '<span>Saving...</span>' the inner HTML of the link will be replaced instead of the link itself. Don't want that. onclick: If I add