I have a rails 3.2 application where I have a table called menu_items. My rails application barks when I read data that has an apostrophe in it (ex "Devil's food cake"). I am able to input the field however reading it is a different story. My application works perfectly as long as I delete the record with the apostrophe. My view is an ajax form where I remotely retrieve the record. My schema is below.
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | YES | | NULL | |
| description | text | YES | | NULL | |
| price | decimal(8,2) | YES | | NULL | |
| serves | varchar(255) | YES | | NULL | |
| measurement | varchar(255) | YES | | NULL | |
| created_at | datetime | YES | | NULL | |
| updated_at | datetime | YES | | NULL | |
| section_id | int(11) | YES | | NULL | |
| position | int(11) | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
Following is the error I receive when trying to edit the record within my application.
ActionView::Template::Error (SyntaxError: reserved word "class" can't be assigned on line 343):
1: $('#edit_form').empty()
2: $('#available_menu_items_container').empty()
3: $('#available_menu_items_container').html('<%= render :partial => "menu_item" %>')
4: $('.new_menu').hide()
app/views/menus/edit.js.coffee:1:in `_app_views_menus_edit_js_coffee__4311426478414483561_70345298165400'
app/controllers/menus_controller.rb:33:in `edit'
According to the error message, you're setting an attribute called class somewhere
ActionView::Template::Error (SyntaxError: reserved word "class" can't be assigned on line 343):
Look at line 343 (I think in your view) for something like
Perhaps you're setting a CSS class?
Really weird that an apostrophe would effect that - I think removing the record with the apostrophe is just hiding this bug rather than solving the issue.
Related
I'm trying to salvage a Gitorious installation that has gone bad. I've dumped the SQL table using mysqldump, but now I'm running into the problem that the new version of Gitorious changed its SQL schema in a few places.
In particular, the old version has a table taggings, which looks like
mysql> describe taggings;
+---------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| tag_id | int(11) | YES | MUL | NULL | |
| taggable_id | int(11) | YES | MUL | NULL | |
| taggable_type | varchar(255) | YES | | NULL | |
| created_at | datetime | YES | | NULL | |
+---------------+--------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
In the new version, this table has gotten three extra columns:
mysql> describe taggings;
+---------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| tag_id | int(11) | YES | MUL | NULL | |
| taggable_id | int(11) | YES | MUL | NULL | |
| taggable_type | varchar(255) | YES | | NULL | |
| created_at | datetime | YES | | NULL | |
| tagger_id | int(11) | YES | | NULL | |
| tagger_type | varchar(255) | YES | | NULL | |
| context | varchar(255) | YES | | NULL | |
+---------------+--------------+------+-----+---------+----------------+
8 rows in set (0.00 sec)
so that
grep 'INSERT INTO `taggings`' inuse.sql | mysql -uroot gitorious_production
fails with
ERROR 1136 (21S01) at line 1: Column count doesn't match value count at row 1
Is there an easy way to tell MySQL that the final two fields should be left at their default value, NULL?
(The new Gitorious' taggings table starts out empty.)
As a general best practice, you should mention the field names in which you're inserting :
Insert into taggings (id,tag_id,taggable_id,taggable_type,created_at) values (...your values...)
Rename your new table taggings as taggings_old
Create a table named taggings with your old schema
Insert your data
Add the new column to your table taggings
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i am trying to create a support system. In which user can raise ticket and our support team will resolve it and user can see our reply. Here point to be noted is i don't want to use any kind of email system. How do i resolve this any help would be thankful.
My table structure below:here ticket number is unique and generate once for every ticket.
+-------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| company_id | int(11) | NO | | NULL | |
| subject | varchar(255) | YES | | NULL | |
| description | text | YES | | NULL | |
| created_by | int(11) | NO | | NULL | |
| created_date | date | YES | | NULL | |
| assigned_to | varchar(255) | YES | | NULL | |
| status_id | int(11) | NO | | NULL | |
| completed_date | date | YES | | NULL | |
| ticket_number | varchar(255) | NO | | NULL | |
| deleted | tinyint(1) | YES | | 0 | |
i got a solution for support ticket. I used separate namespace for admin and seperate table for support ticket, now a use can generate ticket and admin is default receiver for that ticket. When admin reply any ticket the user who created the ticket will be the receiver.
I want to store a large number of filled-out government forms, like the Application for Federal Assistance. The forms are varied and change yearly. Field types vary, and can be: boolean, string, date, int, among others.
Is the best way to store these forms to completely normalize data?
À la:
form
+-----------------+-----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| govt_identifier | char(40) | YES | | NULL | |
| description | char(100) | YES | | NULL | |
+-----------------+-----------+------+-----+---------+----------------+
filled_form (a form a person has actually filled out)
+-----------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| form_id | int(11) | NO | | NULL | |
| person_id | int(11) | NO | | NULL | |
+-----------+---------+------+-----+---------+----------------+
text_field (a class of input; belongs to a form)
+---------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | char(40) | YES | | NULL | |
| form_id | int(11) | NO | | NULL | |
+---------+----------+------+-----+---------+----------------+
text_value (a particular input record; belongs to a class and filled_form)
+----------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| value | text | YES | | NULL | |
| text_field_id | int(11) | NO | | NULL | |
| filled_form_id | int(11) | NO | | NULL | |
+----------------+---------+------+-----+---------+----------------+
... continue for all input types
While this would work, your SQL will be slightly awkward and quite non-intuitive. Have you considered actually creating data models for each form individually and then using those to populate your forms. It may seem more work up front, but the development of your data capture will potentially be simpler.
I would have a look at single table inheritance.
Model each field as a base class Field with subclasses IntField, BoolField, etc.
The Field class will have a member Name (string), IntField will have IntValue (int), BoolField will have BoolValue (bit), etc.
This requires you to have one column for each possible type in your Field-table, that is a bit space overhead, but on the other hand it gives you type safety. If you model as single table inheritance you can probably hook up your favorite ER-mapper without problem.
query:
SELECT u.deviceID, u.userName, u.contactNo, u.rating
FROM User u
INNER JOIN TaxiQuery t ON u.deviceID = t.seat1
OR u.deviceID = t.seat2
OR u.deviceID = t.seat3
OR u.deviceID = t.seat4
WHERE t.queryID = 3;
+--------------------------------------+----------+-----------+--------+
| deviceID | userName | contactNo | rating |
+--------------------------------------+----------+-----------+--------+
| 00000000-0000-1000-8000-0016CB8B3C8E | uuuuuu | 55555 | 5 |
+--------------------------------------+----------+-----------+--------+
describe user;
+-----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| deviceID | varchar(100) | NO | PRI | NULL | |
| userName | varchar(100) | YES | | NULL | |
| contactNo | int(11) | YES | | NULL | |
| emailAddr | varchar(100) | YES | | NULL | |
| rating | int(11) | YES | | NULL | |
+-----------+--------------+------+-----+---------+-------+
mysql> describe taxiQuery;
+--------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+----------------+
| queryID | int(11) | NO | PRI | NULL | auto_increment |
| destination | varchar(100) | YES | | NULL | |
| deptTime | varchar(100) | YES | | NULL | |
| startingPt | varchar(100) | YES | | NULL | |
| boardingPass | varchar(100) | YES | | NULL | |
| miscInfo | varchar(100) | YES | | NULL | |
| seat1 | varchar(100) | YES | | NULL | |
| seat2 | varchar(100) | YES | | NULL | |
| seat3 | varchar(100) | YES | | NULL | |
| seat4 | varchar(100) | YES | | NULL | |
+--------------+--------------+------+-----+---------+----------------+
What i want is to display the user's information if they exist in (seat1/seat2/seat3/seat4) in TaxiQuery. But i am only able to output one result when they are suppose to be three.
May i know how do i modify mysql statement to display the user's information when (seat1-4 is the foreign key to the deviceID of User's table) when seat1, seat2, seat3, seat4 contains the deviceID of the users?
As far as I can tell, it should work if you don't do an INNER join. I think the INNER keyword is telling mySQL to only include each source a maximum of once, so it will only use one copy of the TaxiQuery, when you actually need up to four (one per seat).
i have user list , and i have select box to filter userlist one of the select box options is show by most viewed so i have also need user information too .
i want to sort my users based on most viewed profile in my user list .
i have these two tables but i don't know how to right correct query to make this happen .
i used grouping like this :
$sql ="select userid , count(*) form profile_visit group by userid " ;
but it's not make sense to me , i don't think this query will help me at all .
+-----------+---------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------------+------+-----+-------------------+----------------+
| userid | int(11) | NO | PRI | NULL | auto_increment |
| username | varchar(128) | NO | | NULL | |
| password | char(40) | NO | | NULL | |
| email | varchar(128) | NO | | NULL | |
| name | varchar(256) | NO | | NULL | |
| lastname | varchar(256) | NO | | NULL | |
| job | varchar(256) | NO | | NULL | |
| birthdate | varchar(100) | NO | | NULL | |
| address | varchar(1024) | NO | | NULL | |
| website | varchar(100) | NO | | NULL | |
| tel | varchar(100) | NO | | NULL | |
| role | tinyint(1) | NO | | 0 | |
| reg_date | timestamp | NO | | CURRENT_TIMESTAMP | |
+-----------+---------------+------+-----+-------------------+----------------+
and profile_visit table like this
+------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| ip_address | varchar(70) | NO | | NULL | |
| userid | int(11) | NO | | NULL | |
+------------+-------------+------+-----+---------+----------------+
Try something like this:
$sql ="SELECT userid , COUNT(*) AS visits FROM profile_visit GROUP BY userid ORDER BY visits DESC" ;
That should group as you were expecting, but order the results in descending order based on the number of visits they have had.
I would ask whether it is necessary to have a separate table? Do you need details of all the visits to be stored, or could you just increment a "visits" integer for each user?
Disregarding the typo in form from your query looks reasonable. It should give you the profile identifiers and their view counts.
As I understand your question, you simply need to get the data out sorted in descending order, which is achievable by simply appending an order by to your query (using an alias for the aggregated column makes it an easier read):
select userid , count(*) as visitcount
from profile_visit
group by userid
order by visitcount