erb

Rails js.erb not working

自闭症网瘾萝莉.ら 提交于 2021-02-11 08:42:53
问题 I'm submitting a form, with somewhat complex nesting to a Rails controller. The Javascript is tied to the submit button as below: $('#new_search').submit(function() { var valuesToSubmit = $(this).serializeArray(); $.ajax({ type: "POST", url: $(this).attr('action'), //sumbits it to the given url of the form data: valuesToSubmit, dataType: "POST" }) return false; // prevents normal behaviour }); The Rails controller handles this fine and the parameters are all where they should be. I'm then

ActionView::Template::Error: ActionView::Template::Error: undefined method `[]' for nil:NilClass

♀尐吖头ヾ 提交于 2021-02-07 08:01:48
问题 I have a basic static webpage. class StaticPagesController < ApplicationController def home end end And there is a home.html.erb with just heading. This works perfectly fine in developement but the test test "should get home" do get :home assert_response :success assert_select "title","home | #{@base}" end is failing with error ActionView::Template::Error: ActionView::Template::Error: undefined method []' for nil:NilClass Its showing error in application.html.erb <%= stylesheet_link_tag

ActionView::Template::Error: ActionView::Template::Error: undefined method `[]' for nil:NilClass

旧巷老猫 提交于 2021-02-07 08:01:42
问题 I have a basic static webpage. class StaticPagesController < ApplicationController def home end end And there is a home.html.erb with just heading. This works perfectly fine in developement but the test test "should get home" do get :home assert_response :success assert_select "title","home | #{@base}" end is failing with error ActionView::Template::Error: ActionView::Template::Error: undefined method []' for nil:NilClass Its showing error in application.html.erb <%= stylesheet_link_tag

what controller data is accessible in html.erb?

被刻印的时光 ゝ 提交于 2021-01-28 18:58:41
问题 I'm trying to understand how the controller class and the .html.erb view files in Rails are connected, and how the view accesses data in the controller methods. For example, I have the following controller class: class SomeController < ApplicationController def show # defining some data to access in the view x = 1 @y = 2 end end If in the corresponding .html.erb view file, I try to access @y , this works fine <p> <%= @y %> </p> However, if I try to access x , it gives an error <p> <%= x %> <

HAML Form For Rails

白昼怎懂夜的黑 提交于 2021-01-27 05:54:27
问题 I'm currently trying to convert an ERB layout to HAML. This is the error I keep receiving: index.html.haml:18: syntax error, unexpected ')' ));}\n #{_hamlout.format_... Here is the HAML page: .row-fluid .span6 %h2 Todo List .span6 %h2{:style => "text-align:right;"} <script>document.write(today)</script> %hr.divider .row-fluid .span6 %h2.small_head New Task = render :partial => 'layouts/form_errors', :locals => {:object => @list} .form = form_for :list, :url => {:controller => 'lists', :action

Rails is adding a </form> tag in a spot that is not where I closed the do block, it is breaking my form

落爺英雄遲暮 提交于 2021-01-27 04:57:11
问题 I'm having one heck of an issue working out how to do this. I have 2 forms that need to be displayed next to each other but you can't embed forms, I got around this by just putting the 2nd form after the first one. However, rails is ignoring my <% end %> tag for the 2nd form and it is auto-closing the 2nd form before it needs to be closed. This is making my form not work. Here's the view with some bits omitted for brevity. <div class="row"> <div class="col-md-3"> <div class="well"> <%= render

Rails is adding a </form> tag in a spot that is not where I closed the do block, it is breaking my form

橙三吉。 提交于 2021-01-27 04:57:07
问题 I'm having one heck of an issue working out how to do this. I have 2 forms that need to be displayed next to each other but you can't embed forms, I got around this by just putting the 2nd form after the first one. However, rails is ignoring my <% end %> tag for the 2nd form and it is auto-closing the 2nd form before it needs to be closed. This is making my form not work. Here's the view with some bits omitted for brevity. <div class="row"> <div class="col-md-3"> <div class="well"> <%= render

Can you get ERB to properly indent when rendered?

。_饼干妹妹 提交于 2020-06-10 13:21:54
问题 I have several partials that I'm including in my Rails application.html.erb file , but the resulting HTML doesn't preserve my indenting (formatting). I've been told that the first line gets rendered with the same indentation-level as the call to _partial.html.erb , but all subsequent lines in the partial just get left-aligned. This results in code like (see my comments for positioning): <body> <div id="outer"> <div class="contentwidth main"> <div class="logo"> <<<<< Shouldn't be this far to

Can you get ERB to properly indent when rendered?

徘徊边缘 提交于 2020-06-10 13:21:51
问题 I have several partials that I'm including in my Rails application.html.erb file , but the resulting HTML doesn't preserve my indenting (formatting). I've been told that the first line gets rendered with the same indentation-level as the call to _partial.html.erb , but all subsequent lines in the partial just get left-aligned. This results in code like (see my comments for positioning): <body> <div id="outer"> <div class="contentwidth main"> <div class="logo"> <<<<< Shouldn't be this far to

How to comment code in Rails views?

删除回忆录丶 提交于 2020-02-23 09:21:05
问题 As I'm playing with Rails and developing views I often want to comment out code. Simple enough with classes & models but views are a bit more tricky. What's best way to comment code in a view so it's not interpreted by, well, anything... HTML gives us <!-- commented Rails code here --> though code enclosed here seems to get interpreted anyway?!? Or is there a more Railsy way? 回答1: <% code code # comment %> USED to work but I think that was accidental. You were always supposed to put comments