erb

Rails: undefined method text_field_tag

僤鯓⒐⒋嵵緔 提交于 2019-12-13 03:44:31
问题 My ERB file works fine if I use text_field , but if I switch to text_field_tag I receive this error: undefined method `text_field_tag' for #<ActionView::Helpers::FormBuilder:0x00000001f6fd50> Here is the code that works: <%= f.text_field mystring %> And the code that does not work: <%= f.text_field_tag mystring %> text_field_tag is documented. How to make it work? Do I need a require or something? 回答1: For your information, text_field_tag is from ActionView::Helpers::FormTagHelper , which

How do you make ruby variables and methods in scope using Thor Templates?

老子叫甜甜 提交于 2019-12-13 00:53:36
问题 I'm trying to use the Thor::Actions template method to generate some C++ test file templates, but erb keeps telling me that I have undefined variables and methods. Here's the calling code: def test (name, dir) template "tasks/templates/new_test_file", "src/#{dir}/test/#{name}Test.cpp" insert_into_file "src/#{dir}/test/CMakeLists.txt", "#{dir}/test/#{name}Test ", :after => "set(Local " end Here's the template: <% test_name = name + "Test" %> #include <gtest/gtest.h> #include "<%= dir %>/<%=

Rails: Automatic inclusion of action/controller specific javascript files?

孤街浪徒 提交于 2019-12-12 15:03:20
问题 I am a beginner at rails development and moved from cakephp. In cakephp there's something you can do in the layout to automatically include any javascript files that are named the same as either the controller or the action. For instance in www.website.com/post/add both post.js and post/add.js will automatically be loaded if they exist. Is there a way to do this in rails? I tried doing a google but didn't know what to search for and didn't turn up much. (Same thing with css) 回答1: I'm not

How to put two divs on the same line with CSS in simple_form in rails?

百般思念 提交于 2019-12-12 08:39:53
问题 Putting two divs on the same line is an old question. But I can't find a solution when working with simple_form in rails. What I want to do is to display content and its label on the same line. The width of the label is 125px ( .left ) and the content is on the right ( .right ). The text in the label is aligned to the right and the text in content is aligned to the left. Here is the HTML: <form id="new_production" class="simple_form new_production" novalidate="novalidate" method="post" action

How do you create pretty json in CHEF (ruby)

余生颓废 提交于 2019-12-12 07:37:41
问题 How would you make an erb template that has human readable json? The following code works, but it makes a flat json file default.rb default['foo']['bar'] = { :herp => 'true', :derp => 42 } recipe.rb template "foo.json" do source 'foo.json.erb' variables :settings => node['foo']['bar'].to_json action :create end foo.json.erb <%= @settings %> Similar SO questions Chef and ruby templates - how to loop though key value pairs? How can I "pretty" format my JSON output in Ruby on Rails? 回答1: As

How do I update my view template once my form is submitted via Ajax in RAILS 4?

怎甘沉沦 提交于 2019-12-12 06:08:20
问题 I am trying to wrap my head around ajax forms in rails and using Remote => True on my forms. Now this works, When I click on Add New Subject. The following will happen 1.form partial will be appended to the body(this has the form in it) 2.Bootstrap Modal will show up with the form on the inside 3. Once I click Submit, the modal will go away, and the data will be stored(success) My problem is that the original Index.html.erb view is now stale, as the data is inserted into my database, the view

Submitting a form (no model) and having trouble getting the controller to play its part

寵の児 提交于 2019-12-12 04:48:21
问题 I’ve created a basic framework for webapps (some static pages, user authentication, unit/integration testing with rspec). I’d like to use this as a foundation for future webapps, but I need to setup a way to rename it after cloning it from github. I got some help generating the renaming code here]1, but I'm struggling to figure out how to integrate it. I originally wrote had the renaming code in a rakefile, but now I think maybe it should be in the controller. Unfortunately, I haven't been

How to get the output of a nested form to stay in its exact original order, despite permutations, using the index action & index template?

蓝咒 提交于 2019-12-12 02:52:48
问题 I am using a nested form to post Urls and Texts. Via javascript, I am allowing any permutation of these two fields e.g. Url1 Text1 Text2 Url2 or Url1 Text1 Url2 Text2 etc After submitting the form and redirecting to the index.html.view, I am then trying to keep the original order of whatever permutation I decide to use in the form i.e. if I decided to post Text1 Url1 Url2 Text2 Url3 I need that exact same arrangement to display in the browser. Post Form Code Post Model class Post <

Rails 3 Possible ERB Bug When Executing Raw SQL/Calling Scopes?

烈酒焚心 提交于 2019-12-12 02:30:26
问题 in my User model I have a scope: scope :with_tournament_entrees, :include => :registers, :conditions => "registers.id IS NOT NULL" I wanted to see the SQL being generated by this scope and it produces: "SELECT \"users\".* FROM \"users\" WHERE (registers.id IS NOT NULL)" I don't see any mention of the include parameter I added and returns an error if executed in the console as raw SQL with the help of ActiveRecord::Base.connection.execute . If I was to query User.with_tournament_entrees in the

Rails time_select set default

爷,独闯天下 提交于 2019-12-12 02:29:11
问题 I am using time_select in a rails view, it looks something like this: <div class="field"> <%= f.label :StartTime, "Start Time" %><br /> <%= f.time_select :StartTime %> </div> I want to set the default time to 09:00 (AM), how would I do that? 回答1: What about setting corresponding model property? def new @session = Session.new @session.StartTime = Time.now.beginning_of_day + 9.hours end Note that in Ruby it's against widely accepted conventions to name methods in PascalCase. StartTime should