Multiple model form - ruby-on-rails-3

Let say that I have an interface for inputting vehicle marketing information
+--------------------+
| Vehicle |
|--------------------|
| | +--------------------------------------------------+
| Marketing info +----->| Marketing info |
+--------------------+ |--------------------------------------------------|
| | | |
| Engine info | | |
+--------------------+ | +--------------------------+ |
| | | Name | | |
| Wheels | | | | |
+--------------------+ | +--------------------------+ |
| | | |
| Doors | | +--------------------------+ |
+--------------------+ | Codename | | |
| | | | | |
| Seats | | +--------------------------+ |
+--------------------+ | |
| +--------------------------+ |
| Disinformation | | |
| | | |
| | | |
| | | |
| +--------------------------+ |
+--------------------------------------------------+
I am in a the first page for that vehicle, I want a vehicle to have it's information save in different tables, for example it can have one marketing_info but many wheels or doors
The problem that I am seeing is that the menu on the left has to link to the related model's forms from the new action so the link helpers will encounter nil id's
If I used just one big form and hid the sections I didn't want the users to see, would that be the best option?
I would also like that form to save as it goes along but then move along the steps in the form, how can I do that? Would I have to redirect to the edit action using an anchor to the next step?
Should I do the following:
One big form with hidden steps, with multiple submit buttons on each step
a step is shown if it is in the anchor i.e #step1 or in the examples case #marketinginfo
I want to save on any of the steps.
Once I have saved I need to be in the edit view

Basically you want multi step form http://railscasts.com/episodes/217-multistep-forms
and nested form bcz info goes into different tables http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html
you can have different action for each step of form fill-up

Related

How to insert a markdown table in IntelliJ IDEA?

I'm using IDEA 2019.3 Ultimate edition which ships with markdown support. I'm trying to insert a table like this:
| Key | Func |
|-------|--------|
| cmd+n | search |
but I found tab not working and IDEA doesn't help to indent the table so I have to manually add lots of -. Is there an efficient way to insert a table in IDEA?
Intellij community edition 2020.3.3
|header 1|header 2|
---|---
|xyz|x|
|xyz|y|
Make sure there is an empty line above the table for it to be rendered:
Some texts:
| Tables | Are | Cool |
|----------|:-------------:|------:|
| col 1 is | left-aligned | $1600 |
| col 2 is | centered | $12 |
| col 3 is | right-aligned | $1 |
(using activedecay's text example)
Works for me in IntelliJ IDEA version 2020.2.3
| Tables | Are | Cool |
|----------|:-------------:|------:|
| col 1 is | left-aligned | $1600 |
| col 2 is | centered | $12 |
| col 3 is | right-aligned | $1 |
Since 2022.1 you can use Code > Generate... > Table or Insert... > Table (cmd-N) to insert tables.
You can checkout official IDEA documentation for table support in Markdown plugin.
I don't think this is possible at the moment.
As a workaround you can use the Markdown Table Generator which lets you generate the markdown code while being able to input data in a normal table.
This does not address the OP's original problem, but hopefully it can help others that arrive here as a result of IDEA not rendering their markdown tables.
In my case I needed to add more - characters on the second line. IDEA seems to require a minimum of 3 dashes in order to display the markdown table.
Incorrect
Input
| Some | Table | Header | Values |
| :-: | :-: | :-- | --: |
| Centre | Centre | Left | Right |
Output
| Some | Table | Header | Values |
| :-: | :-: | :-- | --: |
| Centre | Centre | Left | Right |
Correct
Input
| Some | Table | Header | Values |
| :---: | :---: | :--- | ---: |
| Centre | Centre | Left | Right |
Output
-----------------------------------
| Some | Table | Header | Values |
| Centre | Centre | Left | Right |
-----------------------------------

PHP Get data from tables that do not have a specific relationship

I have two tables (CONTROL & PAYMENT) that looks like this:
CONTROL PAYMENT
+--------------------------+ +------------------------+
| CNUMBER | SERIAL | | NUMBER | STATUS |
+--------------------------+ +------------------------+
| C-200-1 | SUDU-03 | | 200 | PAID |
| C-201-1 | SUDU-03 | | 201 | PAID |
| C-202-1 | SUDU-03 | | 202 | PROCESSING|
| C-203-1 | SUDU-03 | | 203 | PAID |
| C-204-1 | SUDU-03 | | 204 | PROCESSING|
| C-204-1 | SUDU-03 | | 205 | PROCESSING|
+--------------------------+ +------------------------+
I want to show a list like this:
+--------------------------+
| CNUMBER | STATUS |
+--------------------------+
| C-200-1 | PAID |
| C-201-1 | PAID |
| C-202-1 | PROCESSING |
| C-203-1 | PAID |
| C-204-1 | PROCESSING |
| C-205-1 | PROCESSING |
+--------------------------+
So, I need get data (SELECT) from table "control" using "serial" (in control table) like a search criteria to find the "status" (in payment table) through "number" (in payment table) using %LIKE% (to match "number" and "cnumber")
I am trying but still I can't figure it out!
I hope someone can help me and give me any idea.
EDIT:
SOLUTION 1:
select c.CNUMBER,p.STATUS from CONTROL c
inner join PAYMENT p on substr(c.CNUMBER,3,3)=p.NUMBER;
Thanks to #Syscall I solved the main problem but I just have a little issue:
How I can show all the values even payment entries are null/empty ?
If the entry on 'control' exist but in 'payment' not
something like that:
+--------------------------+
| CNUMBER | STATUS |
+--------------------------+
| C-200-1 | PAID |
| C-201-1 | | <--empty
| C-202-1 | PROCESSING |
| C-203-1 | PAID |
| C-204-1 | | <--empty
| C-205-1 | PROCESSING |
+--------------------------+
EDIT 2:
SOLVED, USING LEFT JOIN
Thanks again #Syscall.
SOLUTION:
select c.CNUMBER,p.STATUS from CONTROL c
left join PAYMENT p on substr(c.CNUMBER,3,3)=p.NUMBER WHERE col1 = '$var'
You could INNER JOIN using SUBSTR :
select c.CNUMBER,p.STATUS from CONTROL c
inner join PAYMENT p on substr(c.CNUMBER,3,3)=p.NUMBER;
Outputs :
+---------+------------+
| CNUMBER | STATUS |
+---------+------------+
| C-200-1 | PAID |
| C-201-1 | PAID |
| C-202-1 | PROCESSING |
| C-203-1 | PAID |
| C-204-1 | PROCESSING |
| C-204-1 | PROCESSING |
+---------+------------+

Suggested naming conventions for Selenium identifiers

I am using selenium page object model to define all the page elements. I am little unconvinced with the naming conventions that I have followed for naming the element and felt too long. Please suggest on this.
#FindBy(xpath = "//tbody[#id='tabview:listComp1_data']/tr/td[1]/div/div[2]")
public WebElement tableCompanyResultsRow;
#FindBy(xpath = ".//*[#id='mttAddId']")
public WebElement buttonAddMap;
#FindBy(xpath = ".//*[#id='ittAddId']")
public WebElement buttonAddItinerary;
#FindBy(xpath = "//div[#id='ajaxStatusPanel_start']/img")
public WebElement imageLoading;
I have been using the below naming conventions for a long time and it helps understand and distinguish the UI elements.
For locators I always prefix loc_ to the variable name. For example: loc_btnExit, etc.
+----------+----------------------------+--------+-----------------+
| Category | UI/Control type | Prefix | Example |
+----------+----------------------------+--------+-----------------+
| Basic | Button | btn | btnExit |
| Basic | Check box | chk | chkReadOnly |
| Basic | Combo box | cbo | cboEnglish |
| Basic | Common dialog | dlg | dlgFileOpen |
| Basic | Date picker | dtp | dtpPublished |
| Basic | Dropdown List / Select tag | ddl | ddlCountry |
| Basic | Form | frm | frmEntry |
| Basic | Frame | fra | fraLanguage |
| Basic | Image | img | imgIcon |
| Basic | Label | lbl | lblHelpMessage |
| Basic | Links/Anchor Tags | lnk | lnkForgotPwd |
| Basic | List box | lst | lstPolicyCodes |
| Basic | Menu | mnu | mnuFileOpen |
| Basic | Radio button / group | rdo | rdoGender |
| Basic | RichTextBox | rtf | rtfReport |
| Basic | Table | tbl | tblCustomer |
| Basic | TabStrip | tab | tabOptions |
| Basic | Text Area | txa | txaDescription |
| Basic | Text box | txt | txtLastName |
| Complex | Chevron | chv | chvProtocol |
| Complex | Data grid | dgd | dgdTitles |
| Complex | Data list | dbl | dblPublisher |
| Complex | Directory list box | dir | dirSource |
| Complex | Drive list box | drv | drvTarget |
| Complex | File list box | fil | filSource |
| Complex | Panel/Fieldset | pnl | pnlGroup |
| Complex | ProgressBar | prg | prgLoadFile |
| Complex | Slider | sld | sldScale |
| Complex | Spinner | spn | spnPages |
| Complex | StatusBar | sta | staDateTime |
| Complex | Timer | tmr | tmrAlarm |
| Complex | Toolbar | tlb | tlbActions |
| Complex | TreeView | tre | treOrganization |
+----------+----------------------------+--------+-----------------+

Setting the position of a tab Scrollbar when updaing the VerticalScroll Value

I am updating a number of controls dynamically on a tabpage within a c# application. The tab page has autoscroll enabled. As you may be aware, when the user has scrolled down it sets the location x=0,y=0 to be at the current x=0,y=0.
so:
+-----------------------------------+
| X |---| X is now 0,0 in terms of setting locations.
| | - |
| |---|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| TEXT | |
| | |
+-----------------------------------+
AND
+-----------------------------------+
| X | | X is now 0,0 in terms of setting locations.
| TEXT | |
| | |
| | |
| | |
| |---|
| | - |
| |---|
| | |
| | |
| | |
| | |
+-----------------------------------+
Therefore I have to save the VerticalScroll.Value, set it to 0, update the controls and then set the VerticalScroll.Value back to the original value.
This works to a degree, the position of the tab form is correct, however the scrollbar doesn't update, so it looks like this:
+-----------------------------------+
| |---|
| TEXT | - |
| |---|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
+-----------------------------------+
Is there any easy way to update the position of the scrollbar?
If I leave it as it is, when the user clicks on the scrollbar again it moves the position back to the top of the tab form. Thanks for any help you can provide.
To answer my own question:
http://msdn.microsoft.com/en-us/library/system.windows.forms.scrollablecontrol.autoscrollposition.aspx

What are segments in Lucene?

What are segments in Lucene?
What are the benefits of segments?
The Lucene index is split into smaller chunks called segments. Each segment is its own index. Lucene searches all of them in sequence.
A new segment is created when a new writer is opened and when a writer commits or is closed.
The advantages of using this system are that you never have to modify the files of a segment once it is created. When you are adding new documents in your index, they are added to the next segment. Previous segments are never modified.
Deleting a document is done by simply indicating in a file which document of a segment is deleted, but physically, the document always stays in the segment. Documents in Lucene aren't really updated. What happens is that the previous version of the document is marked as deleted in its original segment and the new version of the document is added to the current segment. This minimizes the chances of corrupting an index by constantly having to modify its content when there are changes. It also allows for easy backup and synchronization of the index across different machines.
However, at some point, Lucene may decide to merge some segments. This operation can also be triggered with an optimize.
A segment is very simply a section of the index. The idea is that you can add documents to the index that's currently being served by creating a new segment with only new documents in it. This way, you don't have to go to the expensive trouble of rebuilding your entire index frequently in order to add new documents to the index.
The segment benefits have been answered already by others. I will include an ascii diagram of a Lucene Index.
Lucene Segment
A Lucene segment is part of an Index. Each segment is composed of several index files. If you look inside any of these files, you will see that it holds 1 or more Lucene documents.
+- Index 5 ------------------------------------------+
| |
| +- Segment _0 ---------------------------------+ |
| | | |
| | +- file 1 -------------------------------+ | |
| | | | | |
| | | +- L.Doc1-+ +- L.Doc2-+ +- L.Doc3-+ | | |
| | | | | | | | | | | |
| | | | field 1 | | field 1 | | field 1 | | | |
| | | | field 2 | | field 2 | | field 2 | | | |
| | | | field 3 | | field 3 | | field 3 | | | |
| | | | | | | | | | | |
| | | +---------+ +---------+ +---------+ | | |
| | | | | |
| | +----------------------------------------+ | |
| | | |
| | | |
| | +- file 2 -------------------------------+ | |
| | | | | |
| | | +- L.Doc4-+ +- L.Doc5-+ +- L.Doc6-+ | | |
| | | | | | | | | | | |
| | | | field 1 | | field 1 | | field 1 | | | |
| | | | field 2 | | field 2 | | field 2 | | | |
| | | | field 3 | | field 3 | | field 3 | | | |
| | | | | | | | | | | |
| | | +---------+ +---------+ +---------+ | | |
| | | | | |
| | +----------------------------------------+ | |
| | | |
| +----------------------------------------------+ |
| |
| +- Segment _1 (optional) ----------------------+ |
| | | |
| +----------------------------------------------+ |
+----------------------------------------------------+
Reference
Lucene in Action Second Edition - July 2010 - Manning Publication