partial

Modifying MVC 3 ViewBag in a partial view does not persist to the _Layout.cshtml

左心房为你撑大大i 提交于 2019-12-17 18:02:05
问题 I am using MVC 3 with the Razor view engine. I want to set some values in the ViewBag inside a Partial View and want retrieve those values in my _Layout.cshtml. For example, when you setup a default ASP.NET MVC 3 project you get a _Layout.cshtml file in the "/Views/Shared" folder. In that _Layout.cshtml the Page Title is set like this: <title>@ViewBag.PageTitle</title> Then in "/Views/Home/About.cshtml" view the contents of the ViewBag are modified: @{ ViewBag.Title = "About Us"; } This works

Rails: Should partials be aware of instance variables?

旧时模样 提交于 2019-12-17 17:26:17
问题 Ryan Bates' nifty_scaffolding, for example, does this edit.html.erb <%= render :partial => 'form' %> new.html.erb <%= render :partial => 'form' %> _form.html.erb <%= form_for @some_object_defined_in_action %> That hidden state makes me feel uncomfortable, so I usually like to do this edit.html.erb <%= render :partial => 'form', :locals => { :object => @my_object } %> _form.html.erb <%= form_for object %> So which is better: a) having partials access instance variables or b) passing a partial

Return similar elements of array in Ruby

妖精的绣舞 提交于 2019-12-13 08:39:52
问题 Say I have such an array: arr = ['footballs_jumba_10', 'footballs_jumba_11', 'footballs_jumba_12', 'footballs_jumba_14', 'alpha_romeo_11', 'alpha_romeo_12', 'alpha_juliet_10', 'alpha_juliet_11'] If I wanted to return duplicates, (assuming any of these strings in the array were exactly identical, I would just return arr.detect{ |a| arr.count(a) > 1 } but, what if I wanted to get only duplicates of the first 10 characters of each element of the array, without knowing the variations beforehand?

Only partialially parse a CSV file with OpenCSV

淺唱寂寞╮ 提交于 2019-12-13 07:03:57
问题 I have a CSV file which I want to parse in Java with OpenCSV's csvreader. To do so I have created a bean object to which the information is mapped. Mine is a bit long so here's an example I got from a tutorial : package net.viralpatel.java; public class Country { private String countryName; private String capital; public String getCountryName() { return countryName; } public void setCountryName(String countryName) { this.countryName = countryName; } public String getCapital() { return capital

Dynamic partial name for an object

南楼画角 提交于 2019-12-13 03:57:21
问题 render @some_object will render Rails.root/app/views/some_objects/_some_object.html.erb Now I want to handle which partial will be rendered depends on its data_type field. For example: class SomeObject < AR::Base # some magick method wich I need to rewrite def partial_name case data_type when "String" "string_template" when "Text" "text_template" else "blank_template" end end end I know there is model_name , i18n_key and some others, which are returnes model name, but which one is used in my

Lucene SpanNearQuery partial matching

两盒软妹~` 提交于 2019-12-13 00:07:04
问题 Given a document {'foo', 'bar', 'baz'}, I want to match using SpanNearQuery with the tokens {'baz', 'extra'} But this fails. How do I go around this? Sample test (using lucene 2.9.1) with the following results: givenSingleMatch - PASS givenTwoMatches - PASS givenThreeMatches - PASS givenSingleMatch_andExtraTerm - FAIL ... import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene

Rails nested polymorphic form with javascripting

谁说我不能喝 提交于 2019-12-12 10:19:33
问题 I want the following on my form: Degree is polymorphic partial with has_many relation to profile. This partial is called by main form - profile. By pressing 'Add a Qualification' user can add as many degrees. I've been able to attach only one degree to profile which is the last one others are all ignored. I even know why it's happening because link_to is not able to pass profile instance. so I have to create new profile in degrees_controller as you can see in my code here. Can final profile

Extracting a .app from a zip file in Python, using ZipFile

冷暖自知 提交于 2019-12-12 10:02:30
问题 I'm trying to extract new revisions of Chromium.app from their snapshots, and I can download the file fine, but when it comes to extracting it, ZipFile either extracts the chrome-mac folder within as a file, says that directories don't exist, etc. I am very new to python, so these errors make little sense to me. Here is what I have so far. import urllib2 response = urllib2.urlopen('http://build.chromium.org/buildbot/snapshots/chromium-rel-mac/LATEST') latestRev = response.read() print

Rails partial in modal (render partial from different model)

给你一囗甜甜゛ 提交于 2019-12-12 08:09:15
问题 I have tried to include a partial into a modal something similar to this Rails Admin when you click on "create language". Now as I have not really found out how the code works there, I tried to do a mix between this Rails - AJAX a Modal Dialog? and something own. The thing is, the partial gets rendered now into the modal. But when I hit "save", the validation will go back to the "normal" create-new view and not show the validation errors directly within the modal. How can I show the

no implicit conversion of ActiveSupport::SafeBuffer into Integer

天涯浪子 提交于 2019-12-12 04:51:52
问题 Here is my partial _new_post.html.haml : = semantic_form_for Post.new, as: :post, url: client_panel_discussion_posts_path(resource), html: { data: { discussion_posts_url: client_panel_active_submission_discussion_url(resource.client_application, id: resource.slug) }, multipart: true}, builder: ActiveAdmin::FormBuilder, remote: true, method: :post do |f| =f.inputs do =f.input :body =f.has_many :attachments do |a| =a.input :s3_url, as: :hidden, input_html: { class: "s3_url" } =a.s3_file_field